Which method is MATLAB use in poly2 to do a curve fitting?

조회 수: 27 (최근 30일)
Yaser Khojah
Yaser Khojah 2020년 6월 11일
편집: John D'Errico 2020년 6월 11일
I'm using fit function to conduct a curve fitting for my data and estimate its equation as below. Now I want to know which method is the MATLAB using. Is this based on lest square error or interpolation? I need more explanation to include this in my thesis. Anyone can help please. Thanks in advance.
[population2,gof] = fit(x,y,'poly2');

채택된 답변

John D'Errico
John D'Errico 2020년 6월 11일
편집: John D'Errico 2020년 6월 11일
The 'poly2' option for fit will use a simple linear least squares solver. (I did verify this fact, as could you have done. Be VERY CAREFUL, if you edit the code to view it, as it can be a dangerous thing. Far too many people have editted code from MATLAB, and then mistakenly introduced bugs into the code, and then saved the file by mistake. Use type instead to view provided code.) As well, you could use the debugger to step down into the code to see exactly what fit does and where it goes for the fit.
Specifically, it creates the appropriate matrix problem for a quadratic model, then uses MATLAB's economy sized QR decomposition to decompose the matrix in an efficient and numerically well posed form. Why a QR? Because this also allows the computation of variances on the parameters, as will be computed later on. Essentially, R then provides a Cholesky factor for the covariance matrix. QR is a numerically stable solver for this class of linear agebra problems.
No column pivoting is performed in the QR. This is the only part that mildly surprised me, in that column pivoting could be performed to make the solve somewhat more stable. However, if your model is that close to the edge of instability that pivoting would help here, then you are trying to fit too high order a polynomial model in the first place. As such, I can accept the choice of no column pivoting done in the solve. (By way of comparison, when I wrote my own polyfitn utility, I did use a column pivoted QR.)
As I said, this is just simple linear least squares though. I'm not sure what you are asking, if it is beyond what I've said here. You can ask if you have some further question on what is done, though I won't be willing to teach a complete course on numerical linear algebra.
  댓글 수: 2
Yaser Khojah
Yaser Khojah 2020년 6월 11일
You answered my question thank you so much John. Another question, for the 'cubicinterp', the interpolation is used instead of the least squares solver?
John D'Errico
John D'Errico 2020년 6월 11일
편집: John D'Errico 2020년 6월 11일
'cubicinterp' refers to interpolation as opposed to approximation. No least squares is involved for cubicinterp. That is generally true for any interpolation. The model will always predict the original data points exactly (to within floating point trash in the least significant bits, something which enters into any numerical computation.)
The only spline inside fit where any form of approximation to your data arises is in the smoothing spline, and you have not asked about that one.
But remember that ANYTHING that is explicitly called interpolation will always predict the data with essentially no error. An interpolant is only worried about what it will do BETWEEN the data points. Be careful if you might download tools from the file exchange, which sometimes seem to incorrectly use terms like interpolation with a great deal of license. You can trust the curve fitting toolbox in this respect. Of course, if you download my tools from the FEX, I would claim you can trust me too. But then, I might want to sell you a used car one day... ;-)

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

추가 답변 (2개)

David Hill
David Hill 2020년 6월 11일
See Polynomial Models in Matlab documentation
  댓글 수: 3
David Hill
David Hill 2020년 6월 11일
Did you look at:
help fitoptions;
Yaser Khojah
Yaser Khojah 2020년 6월 11일
Thanks so much this helps too.

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


Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020년 6월 11일
% -- FT is a string or a FITTYPE specifying the model to fit.
%
% If FT is a string, then it may be:
%
% FITTYPE DESCRIPTION
% 'poly1' Linear polynomial curve
% 'poly11' Linear polynomial surface
% 'poly2' Quadratic polynomial curve
% 'linearinterp' Piecewise linear interpolation
% 'cubicinterp' Piecewise cubic interpolation
% 'smoothingspline' Smoothing spline (curve)
% 'lowess' Local linear regression (surface)
%
  댓글 수: 1
Yaser Khojah
Yaser Khojah 2020년 6월 11일
Dear Refael, I have already seen this and I know i'm using 'poly2' which is the Quadratic polynomial curve but I'm not sure if that is enough. Is there anyway, I can get more informaiton. I have seen some other places in goolge that MATLAB is using methods as lest square error or interpolation. However, I do not know here how to get more details?

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by