As I mentioned in the comments, there is a difference between installing a linear model in the log space compared to fitting a non-linear model (as in the sense of least squares).
There is a nice demo in the Statistics toolbar that explains the situation. I am adapting the code below:
%# sample data x = [5.72 4.22 5.72 3.59 5.04 2.66 5.02 3.11 0.13 2.26 ... 5.39 2.57 1.20 1.82 3.23 5.46 3.15 1.84 0.21 4.29 ... 4.61 0.36 3.76 1.59 1.87 3.14 2.45 5.36 3.44 3.41]'; y = [2.66 2.91 0.94 4.28 1.76 4.08 1.11 4.33 8.94 5.25 ... 0.02 3.88 6.43 4.08 4.90 1.33 3.63 5.49 7.23 0.88 ... 3.08 8.12 1.22 4.24 6.21 5.48 4.89 2.30 4.13 2.17]'; xx = linspace(min(x), max(x), 100); %# linear regression in log-space %# y = p2 * exp(p1*x) %# => log(y) = log(p2) + p1*x p_exp = polyfit(x, log(y), 1); yy1 = exp(p_exp(2)) .* exp(xx .* p_exp(1)); %# linear regression p_lin = polyfit(x, y, 1); yy2 = polyval(p_lin, xx); %# non-linear regression (using previous result as initial coeff) f = @(p,x) p(2)*exp(p(1)*x); p_nonlin = nlinfit(x, y, f, [p_exp(1) exp(p_exp(2))]); yy3 = f(p_nonlin, xx); plot(x,y,'o', xx,yy1,'-', xx,yy2,'-', xx,yy3,'-') legend({'data points','linear in log-space','linear','non-linear'})

Amro
source share