필터 지우기
필터 지우기

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 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