polyfit step by step or analytics

조회 수: 3 (최근 30일)
Luca
Luca 2024년 4월 5일
댓글: John D'Errico 2024년 4월 5일
Hello
x = array of max 10 items
y = array of max 10 items
x and y has the same length
i use polyfit(x,y,3)
i get the desired result
but there is a way to have all the steps done for reach the result, or there is a way to have the analytic result?
Thanks
  댓글 수: 2
Steven Lord
Steven Lord 2024년 4월 5일
but there is a way to have all the steps done for reach the result
For what purpose are you hoping to see "all the steps"? Is it for pedagogical purposes (to learn what polyfit does) or is it for some other reason?
If the former, see the Algorithms section on the polyfit documentation page or the Least Squares chapter in Cleve Moler's Numerical Computing with MATLAB.
John D'Errico
John D'Errico 2024년 4월 5일
I don't think a step by step explanation of what polyfit does will help you, at least not without an understanding of the linear algebra, but also of MATLAB itself. You are admittedly a MATLAB novice, so much of what happens inside polyfit will seem quite strange, since it worries about things like tall arrays, etc.
Anyway, that suggests to not worry about exactly what the code does, but to go instead to a good text on numerical linear algebra. Start with the Moler text as suggested by @Steven Lord.

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

답변 (1개)

Bruno Luong
Bruno Luong 2024년 4월 5일
polyfit is the mfile you can step through in debugging mode.
If you call with one outout argument (non normalized) it build vandermond matrix of size 10 x 4 then solve least square linear
system.
There is a formula for 4 x 4 system but it will have a moderately long formula.
  댓글 수: 2
Luca
Luca 2024년 4월 5일
sorry but how i can debug i'm totally new
Thanks
Bruno Luong
Bruno Luong 2024년 4월 5일
편집: Bruno Luong 2024년 4월 5일
Start reading the debug doc
Then type this in MATLAB command window to see what polyfit does.
dbstop in polyfit
x = 1:10;
P = 1:4;
y = polyval(P, x);
polyfit(x, y, 3);

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by