Using the \ operator to fit a parabolic curve to a data set.

31 vues (au cours des 30 derniers jours)
Petch Anuwutthinawin le 20 Juil 2021
Commenté : John D'Errico le 20 Juil 2021
%for a certain file, the first column is the independent variable and
%second is the dependent variable.
h=C([2:13],1);
x=[h ones(length(h),1)] %I use a column of ones in order to simulate a constant secondary dependent variable.
y=C([2:13],2); % the dependent variable
V=x\y %This command only gives me one value, that is just a linear fit. How do I make this use a parabolic fit instead?
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

Torsten le 20 Juil 2021
Replace x by
x = [h.^2 h ones(length(h),1)]
2 commentairesAfficher AucuneMasquer Aucune
Tesfaye Girma le 20 Juil 2021
yhat = (M'*M)\(M'*x);
John D'Errico le 20 Juil 2021
@Tesfaye Girma - NO. Don't tell people to use an inferior method to estimate a linear regression model.
In MATLAB, it is correct to use this:
coef = M\x;
Use of the normal equations (what you showed) will cause significantly increased sensitivity to poorly conditioned problems. That scheme will completely fail to work on many solvable problems.

Connectez-vous pour commenter.

Plus de réponses (1)

Simon Chan le 20 Juil 2021
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear and Nonlinear Regression 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