Reputation: 3
I am getting quite poor results of exponential curve fitting in Matlab. In excel, exponential trendline yields excellent results (imho). What I'm doing wrong in Matlab?
example dataset:
1,0 1,0 0,8 0,8 0,8 0,8 1,1 1,1 0,9 0,9 0,8 0,8 0,8 0,8 0,7 0,7 0,6 0,6 0,7 0,7 1,1 1,1 1,0 1,0 0,9 0,9 0,8 0,8 0,9 0,9 2,1 2,1 1,9 1,9 2,1 2,1 6,5 6,5 6,0 6,0 5,7 5,7 6,4 6,4 11,1 11,1 10,9 10,9 10,2 10,2 8,5 8,5 12,6 12,6 11,8 11,8 9,9 9,9 11,6 11,6 10,6 10,6 9,7 9,7 9,6 9,6 8,2 8,2 10,1 10,1 9,0 9,0 9,0 9,0 8,9 8,9 8,9 8,9 8,2 8,2 11,8 11,8 15,8 15,8 13,1 13,1 14,8 14,8 13,4 13,4 13,6 13,6 15,4 15,4 16,9 16,9 16,7 16,7 25,9 25,9 23,4 23,4 24,5 24,5 26,6 26,6 24,2 24,2 22,7 22,7 21,2 21,2 21,0 21,0 17,3 17,3 42,1 42,1 40,8 40,8 41,3 41,3 39,7 39,7 42,4 42,4 42,6 42,6 89,0 89,0 196,2 196,2 228,1 228,1 385,4 385,4 746,7 746,7 701,8 701,8 633,7 633,7 1051,2 1051,2 1083,1 1083,1 1034,6 1034,6 1096,0 1096,0 1010,5 1010,5 1001,5 1001,5 835,6 835,6 886,1 886,1 1038,2 1038,2 867,4 867,4 821,8 821,8 753,8 753,8 704,5 704,5 616,4 616,4 555,5 555,5 854,1 854,1
yields
y = 0,4734*e^0,0442x, hence a = 0,4734 and b = 0,0442
but in Matlab, with code:
curveFitValues = fit(xdata,ydata,'exp1');
a = curveFitValues.a;
b = curveFitValues.b;
yields
y = 8,6631*e^0,0280x, hence a = 8,661 and b = 0,0280
which is not satisfying result, as seen in image below:
What I'm doing wrong?
P.S: I need to do exponential curve fitting into millions of datasets and trying to find fastest algorithm, any ideas which is fastest way?
Upvotes: 0
Views: 53
Reputation: 388
I have managed to fit your data by using the polyfit
function. I don't have the Curve Fitting Toolbox, but simply using polyfit
serves me well usually. I stored your data as the variable x
in my code.
t = 1:numel(x);
p = polyfit(t, log(x), 1);
figure; hold on
plot(x)
plot(t, exp(p(2)) * exp(p(1)*t))
set(gca, 'yscale', 'log')
hold off
This code takes ln(x)
and fits it to t
using a least squares method. Then you just convert back when you produce the plot.
p
has values p(1) = 0.0442
and exp(p(2)) = 0.4375
.
Upvotes: 1