Effacer les filtres
Effacer les filtres

Estimating two coefficients out of three in quadratic function

1 vue (au cours des 30 derniers jours)
MariapL
MariapL le 19 Nov 2017
Commenté : Star Strider le 19 Nov 2017
Hi Everybody, I need to estimate coefficients of this equation aN^2 + bN. It is standard quadratic function but coefficient c=0. My data is a time series, where:
x= [ 0, 5 ,9, 10,15, 16]
y= [715,901, 1139, 1224,1553,1712]
F=polyfit(x,y,3)
plot(F)
As you can see I am using polyfit, which gives me 3 coefficients: a=1.9029 b=30.1841 c=712.7646. I need c to be 0. Do you know any way to calculate only a and b, setting c as 0? I will much appreciate your help, as i am stuck a bit. Thank you :)

Réponse acceptée

Star Strider
Star Strider le 19 Nov 2017
Try this:
x= [ 0, 5 ,9, 10,15, 16];
y= [715,901, 1139, 1224,1553,1712];
F = [x(:).^2 x(:)]\y(:);
eqnstr = sprintf('F(x) = %.2f\\cdotx^2 + %.2f\\cdotx', F)
xv = linspace(min(x), max(x));
figure(1)
plot(x, y, 'pg')
hold on
plot(xv, polyval([F(:)' 0],xv), '-r')
hold off
grid
text(3, 1300, eqnstr)
  10 commentaires
MariapL
MariapL le 19 Nov 2017
It works too :) I deal with it by putting text(800,100,..) now its visible, becouse this point is actually on my plot. After I changed data the whole plot moved. :)
Star Strider
Star Strider le 19 Nov 2017
As long as it works in your code, it’s correct!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by