필터 지우기
필터 지우기

poly and polyval for large vectors...

조회 수: 2 (최근 30일)
David Pesetsky
David Pesetsky 2018년 7월 23일
댓글: David Pesetsky 2018년 7월 23일
Hello,
I need to get the equation of the polynomial through 50 points... a 49th order should make a perfect fit. This doesn't do it:
(load x and y vectors with unique monotonically increasing values...then:)
[p,S,mu] = polyfit(x,y,49);
yp = polyval(p,x);
There is some advice to use "centering and scaling" from the warning message. Using HELP I see:
[P,S,MU] = polyfit(X,Y,N) finds the coefficients of a polynomial in
XHAT = (X-MU(1))/MU(2) where MU(1) = MEAN(X) and MU(2) = STD(X). This
centering and scaling transformation improves the numerical properties
of both the polynomial and the fitting algorithm.
I'm not sure how to follow that advice. Is the an example where a large number of points is used with a poly that should capture them perfectly?
Thanks for helping.

채택된 답변

Guillaume
Guillaume 2018년 7월 23일
편집: Guillaume 2018년 7월 23일
The documentation of polyfit has an example of how to use the centering and scaling option. You need to use that returned mu in polyval for it to make sense:
[p, ~, mu] = polyfit(x, y, 49);
yp = polyval(p, x, [], mu);
This is way outside my area of expertise but I believe that fitting a 49 degree polynomial to 50 points is not an appropriate way to fit data. You probably would be better off fitting splines.
  댓글 수: 1
David Pesetsky
David Pesetsky 2018년 7월 23일
That gives MUCH better answers... if I use an order of 50 rather than 49. I have 50 points, so I'd think that's slightly over-specified... but good for now.
I'll need to check out splines if poly doesn't work.
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by