MATLAB Answers

Strange curve fitting with large polynomial degrees when using polyfit

조회 수: 2(최근 30일)
More Sa
More Sa 2021년 5월 13일
답변: Star Strider 2021년 5월 13일
I'm trying to fit a curve to my points by using polyfit, I'm getting normal results for small polynomial degrees, but when i want to use polyfit for bigger polynomial degrees, I get strange results.
This is what I get when for degree of 10:
It's okay and its normal, but when I use polyfit for the degree of 100, I get strange results for the starting points and the ending points:
What's the reason for this strange behavior? How can i fix this?


Star Strider
Star Strider 2021년 5월 13일
As a general rule, a polynomial fit with a degree grater than 7 is likely not appropriate, so a 100 degree polynomial is giving the expected result, with ‘ringing’ at the extremes.
It would appear that fitting a sine curve to the data would be appropriate. One approach to that is described in Curve fitting to a sinusoidal function. The one change I would make in that code is to replace the ‘zci’ fundtion with this one:
zci = @(x) find(diff(sign(x)));
It is more robust, and does not have the ‘end effect’ my original function does.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by