Hello everyone, anyone knows how to approximate a data with polynomial of degree 8 using least square method?
Show older comments
Polynomial degree is 8 and it should be approximated piecewise.
- y = a0t0 + a1t1 + a2t2 +… + antn ………………………….. (1)
Data description:
The first column is Time(GPS format) unit is seconds.
Second column is y values, so I have to find the coefficients (a0, a1...). And this should be done peicewise (9 points), then iterate this method till the end of the data.
Data is attached.
5 Comments
Matt J
on 24 Jun 2021
You mean an 8th order smoothing spline?
Mohammad Shafi Nikzada
on 25 Jun 2021
dpb
on 25 Jun 2021
An 8th order polynomial through 9 points is exact through the points -- of course, it may be give completely unreasonable responses/predictions between those points and will not be continuously differentiable at the breakpoints.
In general this is aBadIdea™
As Matt J says, an interpolating or smoothing spline would likely be a better choice and a lot less cumbersome to deal with than a zillion separate 8-degree polynomials as the spline toolset will encapsulate the breakpoints and all much more neatly for you.
But, no, you don't get a set of coefficients just like the polynomial coefficients; they're in there but built into the spline object.
What use do you think you'll be making of the coefficients, themselves, anyways, other than plugging into the equation to evaluate?
Mohammad Shafi Nikzada
on 25 Jun 2021
Answers (2)
Walter Roberson
on 25 Jun 2021
1 vote
Loop, moving one point at a time. At each location use polyfit on 9 points to create coefficients. polyder() https://www.mathworks.com/help/matlab/ref/polyder.html and evaluate to get velocity. polyder() again and evaluate to get acceleration.
Then move one point further on.
David Hill
on 25 Jun 2021
Edited: David Hill
on 25 Jun 2021
Use polyfit, place the x and y columns of your data into the function.
p=polyfit(x,y,8);%you will need to convert time using datenum and likely normalize
Categories
Find more on Polynomials 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!