I have the following data
x = [14 18 22 26];y = [8.5588 14.3430 21.6132 30.3740];
and I want to find the slope of this data when it is plotted on a loglog() plot. I tried two methods:
First method:
loglog(x,y);
then go to tools > basic fitting > linear fitting
the result is
y = p1*x + p2 Coefficients: p1 = 1.8179 p2 = -17.636Norm of residuals = 1.4883
slope = 1.8179
Second method:
coeffs = polyfit(log(x),log(y),1); slope = coeffs(1);
by this method
slope = 2.0462
Why is it so? The slope that I find by using first method is closer to the experimental results. Is there any way to do the first method through code instead of GUI?
Best Answer