フィルターのクリア

Curve fitting: plot of curve expression is not as expected

4 ビュー (過去 30 日間)
Giles_T_R_Abbbit
Giles_T_R_Abbbit 2016 年 2 月 21 日
コメント済み: Giles_T_R_Abbbit 2016 年 3 月 31 日
Hi, I fear I may be missing something when using the curve fitting toolbox.
My data consists of the x,y coordinates of the zero contour of a surface. I need to find the mathematical expression of the curve.
Thus, I have interactively used the curve fitting toolbox and have apparently fitted a 6th order polynomial to my data - that passes neatly through all points:
Linear model Poly6:
f(x) = p1*x^6 + p2*x^5 + p3*x^4 + p4*x^3 + p5*x^2 +
p6*x + p7
where x is normalized by mean 2932 and std 1198
Coefficients (with 95% confidence bounds):
p1 = 0.0003037 (0.000286, 0.0003214)
p2 = -0.0007371 (-0.0007531, -0.0007211)
p3 = 0.0003613 (0.0002911, 0.0004315)
p4 = -0.00124 (-0.001291, -0.00119)
p5 = 0.006244 (0.00617, 0.006318)
p6 = -0.02178 (-0.02181, -0.02174)
p7 = 0.2955 (0.2954, 0.2955)
Goodness of fit:
SSE: 1.534e-06
R-square: 1
Adjusted R-square: 1
However, when I try and plot the expression of the curve outside of the interactive toolbox - over exactly the same range of x values, it couldn't be further out: the values on the y-axis are far far too high and the whole curve has been reflected in the y axis...
Can anybody please advise? Thank you
(Oh, I am using Matlab 2015b)
  1 件のコメント
Star Strider
Star Strider 2016 年 2 月 21 日
‘... when I try and plot the expression of the curve outside of the interactive toolbox ...’
Care to share that code with us?

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2016 年 2 月 21 日
The fit centers and scales the X data before evaluating the polynomial. If you fail to perform this step before evaluating the curve, your plot and the plot of the fit will not match -- and since you're taking sixth powers of numbers between 1000 and 5000 the difference can be significant.
  2 件のコメント
Star Strider
Star Strider 2016 年 2 月 21 日
Good point. I don’t have the Curve Fitting Toolbox, so I don’t know what conditioning it performs before it does the fit. The appropriate analogue for polyfit would be the three-output option, and we don’t have the scaling and centreing information necessary to reproduce the fitted curve.
Giles_T_R_Abbbit
Giles_T_R_Abbbit 2016 年 3 月 31 日
Juts to follow up on this, the following can be used to fit the polynomial and evaluate the polynomial at the scaled and centred points:
[J, K, L] = polyfit(xcoords, ycoords, 5);
N = polyval(J, xcoords, [], L);

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2016 年 2 月 21 日
編集済み: John D'Errico 2016 年 2 月 21 日
Were you using MATLAB 2100, it would not matter.
When you try to extrapolate a polynomial, what do you expect it to do? The curve was fit only over a restricted domain. It will fit the set of points you gave it.
Evaluate that polynomial beyond the support of the data, and expect virtually random crap. That is effectively what you said you got. So why are you surprised?
Or, perhaps you are trying to reproduce the polynomial using the coefficients as they are reported to only 5 digits of accuracy. Again, expect crapola. You need to use the exact numbers there, not 5 digit approximations thereof. Again, no surprise. Or there should not be any.
  1 件のコメント
Giles_T_R_Abbbit
Giles_T_R_Abbbit 2016 年 2 月 21 日
when trying to plot the expression, I am not extrapolating past the extremes of the data - as you have assumed. The x values of the data range from 1000 - 5000. Plotting the expression over the same range of values gives the wrong curve I describe. I have updated my question to show this.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by