Reputation: 8211
I have some measurement data which I want to plot. I plot only the points and used the Curve Fitting
Toolbox to generate a regression function which I plot.
Now I want to calculate and plot the tangent on a certain point. How can I do that using Matlab
?
Upvotes: 2
Views: 951
Reputation: 8211
With the help of @0x90 I got the solution:
zerocross = ceil(fzero(fit, 1000));
x_tan = zerocross-101:0.1:zerocross+100;
y_tan = feval(fit, x_tan);
k = (diff(y_tan) ./ diff(x_tan));
k = k(length(k) / 2); % get zero point
d = y_tan(5)-x_tan(5)*k;
plot (x_tan, (k*x_tan+d));
Upvotes: 1
Reputation: 41022
If you have point and function, you can calculate the tangent which is:
let say the desired index is 5. y = mx+n
m = (diff(y) ./ diff(y)) (5)
n = y(5)-x(5)*m
and then
hold on
plot (x, (m*x+n));
links:
http://www.kxcad.net/cae_MATLAB/toolbox/curvefit/bqxox7w.html http://www.weizmann.ac.il/matlab/toolbox/curvefit/cfit.html http://www.mathworks.com/matlabcentral/newsreader/view_thread/170100
Upvotes: 2