I have an array of data which, when plotted, looks like this.
I need to use the polyfit
command to determine the best fitting exponential for the time roughly between 1.7
and 2.3
. I must also compare this exponential fit to a simple linear fit.
I'm given the equation Temp(t) = Temp0 * exp(-(t-t0)/tau)
, where t0
is the time corresponding to temperature Temp0
(I can select where to begin my curve-fitting, but it must be confined to the area roughly between 1.7 and 2.3). Here is my attempt.
% 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)
My exponential fit ends up looking like . My linear fit looks like . (virtually identical). What am I doing incorrectly? Should the two fits be so similar? I am told that circshift
may help, but I couldn't grasp the applicability of the command after reading the help file.