필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Polyfit does not seem to be operating correctly 2011b(7.13.0.564)

조회 수: 1 (최근 30일)
Jack
Jack 2012년 7월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
figure(500)
x = (0: 0.1: 2.5)';
y = erf(x);
[p,S,mu] = polyfit(x,y,6);
BestFit = polyval(p,x);
plot(x,y,'o',x,BestFit,'x');
grid on;
p =
0.0017 -0.0092 0.0016 0.0708 -0.1747 0.1822 0.9230
Correct Solution:
p =
0.0084 -0.0983 0.4217 -0.7435 0.1471 1.1064 0.0004
This is the example from the help page for polyfit.

답변 (1개)

Star Strider
Star Strider 2012년 7월 19일
If you request ‘S’ and ‘mu’ from ‘polyfit’, you need to provide them to ‘polyval’ as well.
BestFit = polyval(p,x,S,mu);
should work. To get everything you asked for from ‘polyfit’ and ‘polyval’, you can also get confidence intervals on the fitted values:
[BestFit, delta] = polyval(p,x,S,mu);
  댓글 수: 2
Jack
Jack 2012년 7월 19일
Consistency between the input and output arguments does produce consistent results from polyval, but asking for mu from polyfit produces incorrect results for p. Why should the results for p depend on the other requested outputs?
Star Strider
Star Strider 2012년 7월 20일
편집: Star Strider 2012년 7월 20일
Requesting ‘S’ and ‘mu’ from ‘polyfit’ asks it to center and scale the x-vector before doing the fit so the fit is more accurate in some situations. Without the additional scaling parameters, ‘polyval’ calculates y-values for an uncentered and unscaled x-vector different from those ‘polyfit’ used to calculate the fit. The polynomial fit parameters are correct in this context, and will of course be different from polynomial fit parameters calculated from an uncentered and unscaled x-vector.

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by