MATLAB: Curve fitting: plot of curve expression is not as expected

curve fittingCurve Fitting Toolbox

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)

Best Answer

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.