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

27 次查看(过去 30 天)
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

Rafael Hernandez-Walls
% -- 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 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by