Curve fitting: plot of curve expression is not as expected
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Giles_T_R_Abbbit
el 21 de Feb. de 2016
Comentada: Giles_T_R_Abbbit
el 31 de Mzo. de 2016
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 comentario
Star Strider
el 21 de Feb. de 2016
‘... when I try and plot the expression of the curve outside of the interactive toolbox ...’
Care to share that code with us?
Respuesta aceptada
Steven Lord
el 21 de Feb. de 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 comentarios
Star Strider
el 21 de Feb. de 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.
Más respuestas (1)
John D'Errico
el 21 de Feb. de 2016
Editada: John D'Errico
el 21 de Feb. de 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.
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!