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

조회 수: 11 (최근 30일)
Laura
Laura 2014년 10월 9일
댓글: Matt J 2014년 10월 10일
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.
  댓글 수: 1
the cyclist
the cyclist 2014년 10월 9일
편집: the cyclist 2014년 10월 9일
This might be useful, but it is not a power law fit, which is what I think Laura is asking for.

댓글을 달려면 로그인하십시오.

카테고리

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