我有一个数据数组,当绘制时,看起来像这样。MATLAB曲线拟合,指数与线性
我需要使用polyfit
命令来大致确定1.7
和2.3
之间的最佳拟合指数的时间。我还必须比较这个指数拟合到一个简单的线性拟合。
我给出的等式Temp(t) = Temp0 * exp(-(t-t0)/tau)
,其中t0
是对应于温度Temp0
时间(I可以选择在何处开始我的曲线拟合,但是它必须大致1.7和2.3之间被限制的区域)。这是我的尝试。
% Arbitrarily defined starting point
t0 = 1.71;
%Exponential fit
p = polyfit(time, log(Temp), 1)
tau = -1./p(1)
Temp0 = exp(p(2))
tm = 1.8:0.01:2.3;
Temp_t = Temp0*exp(-(tm)/tau);
plot(time, Temp, tm, Temp_t)
figure(2)
%Linear fit
p2 = polyfit(time, Temp, 1);
Temp_p = p2(1)*tm + p2(2);
plot(time, Temp, tm, Temp_p)
我的指数拟合最终看起来像。我的线性适合看起来像。 (几乎相同)。我做错了什么?如果两者适合如此相似?我听说circshift
可能会有所帮助,但在阅读帮助文件后,我无法掌握该命令的适用性。
来自@Amro的链接似乎已被The MathWorks打破。更新版本是[here](http://www.mathworks.com/help/stats/examples/curve-fitting-and-distribution-fitting.html)。 – horchler
Thanks @horchler,这里是我前面提到的示例的更新链接:[通过转换为线性拟合非线性模型的陷阱](http://www.mathworks.com/help/stats/examples/pitfalls-in- fitting-nonlinear-models-by-transforming-to-linearity.html) – Amro