What is the highest order polynomial I can use in the polyfit function?
39 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Clayton Birchenough
le 3 Mai 2016
Réponse apportée : Roland
le 3 Juil 2019
Hey all!
I am running a program I've made to calculate missile intercept trajectories. Currently, I have a set of data points that are given to the intercepting missile before it launches which are fit to a polynomial using polyfit. I am evaluating the polynomial to the 85th order, but I was wondering if I can evaluate it to a higher order. It is getting more and more accurate, but for some reason when I enter a larger order than 85, such as 95, it returns the polynomial's coefficients as NaN. Any reason to this? Just curious thanks!
0 commentaires
Réponse acceptée
Image Analyst
le 3 Mai 2016
If you have N data points in your 1-D array, theoretically you can use a polynomial up to order N-1. So 2 points for a line (order 1). With 3 points you can get a quadratic (order 2). And so on. Have you ever seen what happens if you fit too high an order? Yes, it will go through the training points better, but in between the training points, it goes totally crazy with HUGE oscillations. In my opinion anything more than about 4 or 5 would be unreliable at any location other than the training points.
0 commentaires
Plus de réponses (4)
Roland
le 3 Juil 2019
As some of the colleagues pointed out, fitting a polynomial of such a high degree is normally not a good idea!
But if you really want to do this in a stable manner, you can use discrete orthogonal polynomials (DOP) for doing so! A toolbox called DOPbox is available here. Within the documentation, there is an example for fitting high degree polynomials to data.
Additionally, if you want to fit values and derivatives simultaneously (up to a high degree) you can have a look into this paper:
- Ritt, R., Harker, M. and O’Leary, P. (2019) ‘Simultaneous Approximation of Measurement Values and Derivative Data using Discrete Orthogonal Polynomials’, arXiv Open Access Journal Article. Available at: http://arxiv.org/abs/1903.10810 (Accessed: 27 March 2019).
0 commentaires
dpb
le 3 Mai 2016
"... larger order than 85, such as 95, it returns the polynomial's coefficients as NaN"
Yeah, what is your range of x and what is the largest of those to the 95th power?
This is the proverbial really, really bad idea...use an interpolating spline or something similar instead.
0 commentaires
Walter Roberson
le 3 Mai 2016
The tests I did a while back suggested that if your data was not too spread out and you used the recentering, that you could use a degree up to roughly 6 less than the length of your data. Roughly. Sometimes you could not get as good as that.
0 commentaires
Clayton Birchenough
le 12 Mai 2016
3 commentaires
Walter Roberson
le 12 Mai 2016
With values ranging from 0 to 300000 then you are going to lose numeric precision for sure with anything larger than quadratic.
dpb
le 13 Mai 2016
Standardizing the data first will help keep the range in bound of machine range but the resolution issue will still be there, indeed.
Voir également
Catégories
En savoir plus sur Splines dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!