What is the highest order polynomial I can use in the polyfit function?
39 ビュー (過去 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!