2

我有一些要绘制的测量数据。我只绘制点并使用Curve Fitting工具箱生成我绘制的回归函数。

现在我想计算并绘制某个点的切线。我怎样才能做到这一点Matlab

4

2 回答 2

2

如果你有点和函数,你可以计算正切,即:

假设所需的索引是 5。y = mx+n

m = (diff(y) ./ diff(y)) (5)
n = y(5)-x(5)*m

接着

hold on

plot (x, (m*x+n));

链接:

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

于 2012-04-22T19:17:42.500 回答
1

在@0x90 的帮助下,我得到了解决方案:

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));
于 2012-04-22T21:00:37.340 回答