Azzera filtri
Azzera filtri

Curve fitting: plot of curve expression is not as expected

4 visualizzazioni (ultimi 30 giorni)
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 Commento
Star Strider
Star Strider il 21 Feb 2016
‘... when I try and plot the expression of the curve outside of the interactive toolbox ...’
Care to share that code with us?

Accedi per commentare.

Risposta accettata

Steven Lord
Steven Lord il 21 Feb 2016
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 Commenti
Star Strider
Star Strider il 21 Feb 2016
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 il 31 Mar 2016
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);

Accedi per commentare.

Più risposte (1)

John D'Errico
John D'Errico il 21 Feb 2016
Modificato: John D'Errico il 21 Feb 2016
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 Commento
Giles_T_R_Abbbit
Giles_T_R_Abbbit il 21 Feb 2016
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by