
How to draw a tangent line on a curve
109 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gulfer Ozcetin
el 26 de Oct. de 2018
Movida: John D'Errico
el 13 de Nov. de 2024
Hello, I am a MATLAB newbie. I have a transfer function of a process and need to derive a two-parameter model using a tangent line. Now I have the graph of it, all I need to do is getting the "most vertical" tangent line as far as I can do. Just thought choosing a random point on the curve and then writing a piece of code for a tangent line might be useful (for example, it can be (6.5,8)). Couldn't find any answer on plotting a tangent line using a graph that comes from a transfer function, I hope someone can help.
Gs1 = tf([1],[1 5 10 10 5 1],'InputDelay',3) step(Gs1)
and this is how the plot looks like:

0 comentarios
Respuesta aceptada
Star Strider
el 27 de Oct. de 2018
One option:
Gs1 = tf([1],[1 5 10 10 5 1],'InputDelay',3);
[y,t] = step(Gs1);
h = mean(diff(t));
dy = gradient(y, h); % Numerical Derivative
[~,idx] = max(dy); % Index Of Maximum
b = [t([idx-1,idx+1]) ones(2,1)] \ y([idx-1,idx+1]); % Regression Line Around Maximum Derivative
tv = [-b(2)/b(1); (1-b(2))/b(1)]; % Independent Variable Range For Tangent Line Plot
f = [tv ones(2,1)] * b; % Calculate Tangent Line
figure
plot(t, y)
hold on
plot(tv, f, '-r') % Tangent Line
plot(t(idx), y(idx), '.r') % Maximum Vertical
hold off
grid

18 comentarios
Arkadiy Turevskiy
el 12 de Nov. de 2024
Editada: Arkadiy Turevskiy
el 12 de Nov. de 2024
I'd like to add that you can also use System Identification Toolbox for this. It has a function procest for estimating process models.
Here is how you can use it in this case:
Gs1 = tf([1],[1 5 10 10 5 1],'InputDelay',3);
[y,t]=step(Gs1);
z=iddata(y,ones(size(y)),t(2)-t(1)); %create data object with step response,
% step input, and sampling time
model=procest(z,'P1D'); % estimate 1st order process model with delay
compare(data,model)

Star Strider
el 13 de Nov. de 2024
@Arkadiy Turevskiy — Interesting!
I’ve used the System Identification Toolbox relatively often, although not procest so far. I’ll keep it in mind.
Más respuestas (0)
Ver también
Categorías
Más información sobre Response Computation and Visualization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!