Fit the Data to a Quadratic Function with a y-offset (y = b+mx^2) error

7 vues (au cours des 30 derniers jours)
Evve Land
Evve Land le 16 Oct 2020
Commenté : Matt J le 16 Oct 2020
How do I fix this error code?
Data Set:
Here is a data set with uncertainties in y-direction
clear
X=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
Y=[4.2,7.5,19.5,32.8,54.2,80.9,112.2,154.5,197.1,248.0,306.3];
dY=[3.2, 5.4, 8.5, 14.6, 23.6, 32.7, 40.7, 41.8, 34.8, 37.9, 23.9];
Fit the Data to a Quadratic Function with a y-offset (y = b+mx^2)
linear_fit='b+m*x^2';% INSERT CODE HERE TO DEFINE THE FIT FUNCTION
start_values=[1.0,4.0];% INSERT CODE HERE TO CREATE THE START VALUES
[f1,gof1]=fit(X',Y',linear_fit,'Start',start_values)% INSERT CODE HERE TO APPLY THE FIT FUNCTION
!Check for missing argument or incorrect argument data type in call to function 'fit'.

Réponse acceptée

Matt J
Matt J le 16 Oct 2020
Modifié(e) : Matt J le 16 Oct 2020
I get no error messages when I run your code. However, you do not need fit() to perform this fit. You can just use polyfit,
p=polyfit(X.^2,Y,1);
m=p(1);
b=p(2);
  2 commentaires
Evve Land
Evve Land le 16 Oct 2020
thank you!
Matt J
Matt J le 16 Oct 2020
You're quite welcome, but please Accept-click the answer to indicate that it addressed the problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Quadratic Programming and Cone Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by