Using polyfit to fit power function including the initial point x=0
Afficher commentaires plus anciens
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.
1 commentaire
Matt J
le 10 Oct 2014
Is m unknown? Does it have to be integer-valued?
Réponses (3)
Star Strider
le 9 Oct 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
le 9 Oct 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.
Chad Greene
le 9 Oct 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 commentaire
the cyclist
le 9 Oct 2014
Modifié(e) : the cyclist
le 9 Oct 2014
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!