
How to draw a tangent line on a curve
71 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gulfer Ozcetin
am 26 Okt. 2018
Verschoben: John D'Errico
am 13 Nov. 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 Kommentare
Akzeptierte Antwort
Star Strider
am 27 Okt. 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 Kommentare
Arkadiy Turevskiy
am 12 Nov. 2024
Bearbeitet: Arkadiy Turevskiy
am 12 Nov. 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
am 13 Nov. 2024
@Arkadiy Turevskiy — Interesting!
I’ve used the System Identification Toolbox relatively often, although not procest so far. I’ll keep it in mind.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Response Computation and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!