1. how can I optimize a polynomial with unknown coefficients and unknown order whose x and y values are known?
2 views (last 30 days)
Show older comments
if the polynomial is y=c0+c1x+c2x^2+c3x^3+................. values of x & y are known and how i can get what is the order and unknown coefficients to fit the given grapgh
1 Comment
Walter Roberson
on 13 Apr 2014
If the x and y values are known, is there any possibility of "noise" when y was found? Or only of numeric round-off ? Is y found by a physical measurement?
Answers (2)
Star Strider
on 13 Apr 2014
2 Comments
Star Strider
on 13 Apr 2014
Edited: Star Strider
on 13 Apr 2014
Upload your (x,y) data as an attachment to your original question.
What process generated your data?
What else have you tried?
Image Analyst
on 13 Apr 2014
Edited: Image Analyst
on 13 Apr 2014
Like Star Strider said, polyfit() will do it. The order you pick is the number of data points minus 1 (e.g. 2 points use 1 to get a line, 3 points use 2 to get a quadratic, etc.). This will ensure that you have the best possible "fit" because the "fitted" curve will go exactly through each and every data point. Of course in between data points and to the left of the left one and to the right of the rightmost one, you'll have huge wild and crazy values.
Please define EXACTLY what "those data are not fit to my given curve" means by showing a screenshot of what you did .
2 Comments
Walter Roberson
on 14 Apr 2014
If you have exact measurements for N positions and N corresponding datapoints, and if you have indefinite precision calculations, then you can construct a polygon of order (N-1) that will fit all of the points perfectly.
In some cases you might also be able to find an exact fit of lower order. Is that the situation for you, that you suspect that there might be some redundant points?
Note that if your data is a finite truncation of infinite values, or if you have any round-off error in the calculation that generated the y, or if even the slightest bit of noise, then finding the redundant points can be spoiled. And if you do not use indefinite precision arithmetic in doing to operations upon the coefficients that you find, then you might end up with a very large error between the predicted values and the actual values.
As a "rule of thumb", by the time you get to order 8 polynomials (9 points) then round off in finite arithmetic will result in inexcusable errors in doing projections. Lower orders will have notable errors as well. Some people say that if you are fitting at higher than order 4 then you are probably making a mistake if you are relying on double precision.
See Also
Categories
Find more on Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!