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

조회 수: 27 (최근 30일)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021년 7월 20일
댓글: John D'Errico 2021년 7월 20일
%for a certain file, the first column is the independent variable and
%second is the dependent variable.
C=xlsread('super.xlsx');
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?

채택된 답변

Torsten
Torsten 2021년 7월 20일
Replace x by
x = [h.^2 h ones(length(h),1)]
  댓글 수: 2
Tesfaye Girma
Tesfaye Girma 2021년 7월 20일
yhat = (M'*M)\(M'*x);
John D'Errico
John D'Errico 2021년 7월 20일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Simon Chan
Simon Chan 2021년 7월 20일

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by