What is the highest order polynomial I can use in the polyfit function?
38 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2016-5-3
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 个评论
更多回答(4 个)
Roland
2019-7-3
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 个评论
dpb
2016-5-3
"... 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 个评论
Walter Roberson
2016-5-3
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 个评论
Clayton Birchenough
2016-5-12
3 个评论
Walter Roberson
2016-5-12
With values ranging from 0 to 300000 then you are going to lose numeric precision for sure with anything larger than quadratic.
dpb
2016-5-13
Standardizing the data first will help keep the range in bound of machine range but the resolution issue will still be there, indeed.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!