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

11 visualizaciones (últimos 30 días)
Laura
Laura el 9 de Oct. de 2014
Comentada: Matt J el 10 de Oct. de 2014
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.

Respuestas (3)

Star Strider
Star Strider el 9 de Oct. de 2014
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 el 9 de Oct. de 2014
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 el 9 de Oct. de 2014
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 comentario
the cyclist
the cyclist el 9 de Oct. de 2014
Editada: the cyclist el 9 de Oct. de 2014
This might be useful, but it is not a power law fit, which is what I think Laura is asking for.

Iniciar sesión para comentar.

Categorías

Más información sobre Fit Postprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by