Ask for fitting data points by power function
显示 更早的评论
Hi every one, I have a small problem with data after experiment. I need to fit it with the power law , when I try with Fit options in Curve fitting tool of Matlab R2013a, I don't know how to Optimize the parameter sets such as StartPoint, Lower, Upper,... to obtain the best fitting curve. Can anybody show me how to do that? I tried to change the value of parameters in Dialog box of Fit options but the fitting curve doesn't seem to change at all :((. I have the data here.
*x = [ 5.45 6.2 10.15 10.9 11.65 15.55 16.3 17.05 20.83 21.58 22.33 26.16 26.91 27.67 31.8 32.6 33.3 37.15 37.9 38.6];
*y = [ 11.23 7.22 6.95 6.7 6.66 5.82 5.76 5.8 5.3 5.11 5.63 5.44 5.82 5.79 5.44 5.65 5.52 5.59 5.55 5.51 ]; Thank you very much. :D
回答(2 个)
Alan Weiss
2015-3-23
编辑:Alan Weiss
2015-3-23
Your data as given doesn't lead to a very good fit. Here is what I found:
xdata = [ 5.45 6.2 10.15 10.9 11.65 15.55 16.3 17.05 20.83 21.58 22.33 26.16 26.91 27.67 31.8 32.6 33.3 37.15 37.9 38.6];
ydata = [ 11.23 7.22 6.95 6.7 6.66 5.82 5.76 5.8 5.3 5.11 5.63 5.44 5.82 5.79 5.44 5.65 5.52 5.59 5.55 5.51 ];
fun = @(x,xdata)x(1)*xdata.^x(2);
x0 = [2,-0.5];
[x,res] = lsqcurvefit(fun,x0,xdata,ydata)
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
x =
14.4106 -0.2930
res =
11.6140
However, plotting the curve showed that the first point looked like an outlier.
plot(xdata,ydata,'ko',xdata,fun(x,xdata),'b-')

Removing the first point gives a better fit.
xd2 = xdata(2:end);
yd2 = ydata(2:end);
[x2,res2] = lsqcurvefit(fun,x0,xd2,yd2)
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
x2 =
9.5469 -0.1618
res2 =
1.6879
figure;plot(xd2,yd2,'ko',xd2,fun(x2,xd2),'b-')

Not great, but better.
I did this using the Optimization Toolbox lsqcurvefit function, but the idea is the same no matter what you use to do the fit.
Alan Weiss
MATLAB mathematical toolbox documentation
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!