Using polyfit to fit power function including the initial point x=0

11 次查看(过去 30 天)
I want to find the equation for data points that are given below
x= [ 0 0.0005 0.001 0.005 0.01 0.05 0.1];
y=[0.43 0.47 0.51 0.77 1 1.9 2.44];
Because the first x component is zero hence I could not include the first data set if I fit it as power function.
Is there a way to fit it as y=y(0) +a*x^m?
Thank you.

回答(3 个)

Star Strider
Star Strider 2014-10-9
You can do a power fit with fminsearch:
x= [ 0 0.0005 0.001 0.005 0.01 0.05 0.1];
y=[0.43 0.47 0.51 0.77 1 1.9 2.44];
xc = linspace(min(x),max(x));
f = @(b,x) b(1).*x.^b(2);
SSE = @(b,f,x,y) sum((y-f(b,x)).^2);
B = fminsearch(@(b) SSE(b,f,x,y), [1;1]);
figure(1)
plot(x, y, 'pr')
hold on
plot(xc, f(B,xc), '-g')
hold off
grid
legend('Data', 'Power Function Fit', 'Location', 'NW')
text(0.05, 1.2, sprintf('\\itf\\rm(\\itx\\rm) = %.1f \\itx\\rm^{%.2f}',B))
producing:

the cyclist
the cyclist 2014-10-9
I assume that you mean you want to fit
y == y0 + a * x^m
and you want to estimate values for y0, a, and m.
If you have the Statistics Toolbox, you can use the nlinfit function to do that sort of fit.

Chad Greene
Chad Greene 2014-10-9
x=[0 0.0005 0.001 0.005 0.01 0.05 0.1];
y=[0.43 0.47 0.51 0.77 1 1.9 2.44];
plot(x,y,'ko')
hold on
linearFit = polyfit(x,y,1);
xfit = linspace(0,.1,100);
yfitLinear = linearFit(1)*xfit + linearFit(2);
plot(xfit,yfitLinear,'b')
secondOrderFit = polyfit(x,y,2);
yfitSecondOrder = secondOrderFit(1)*xfit.^2 + secondOrderFit(2)*xfit + secondOrderFit(3);
plot(xfit,yfitSecondOrder,'r')
legend('original data','linear fit','second order fit','location','southeast')
legend boxoff
box off
You could do whatever power of fit you'd like.

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by