about polyval and polyfit
이전 댓글 표시
y=[22.9000
23.2000
23.0000
24.4000
26.7000
25.0000
25.5000
26.3000
26.1000
26.2000
27.0000
26.3000
28.1000
26.4000
27.8000]';
x1=1:15;
x2=11:25;
x3=22:36;
x4=11111:11125;
y1=polyval(polyfit(x1,y,14),x1);
y2=polyval(polyfit(x2,y,14),x2);
y3=polyval(polyfit(x3,y,14),x3);
y4=polyval(polyfit(x4,y,14),x4);
then,why y1,y2,y3,y4 are quite different?
I think,theoretically they are exactly y.
Thanks for any help.
채택된 답변
추가 답변 (2개)
Wayne King
2011년 10월 9일
Hi XU,
Keep in mind that polyfit() is fitting the best polynomial in the least-squares sense. You are trying to fit a polynomial with the same y-values but for vastly different values of x, so why do you expect the fit to be exactly the same?
Further, these are badly-conditioned fits. Reduce the order of your polynomial to 3 (for example) and see what happens for y1 to y3. (y4 is still badly conditioned).
y=[22.9000 23.2000 23.0000 24.4000 26.7000 25.0000 25.5000 26.3000 26.1000 26.2000 27.0000 26.3000 28.1000 26.4000 27.8000];
x1=1:15;
x2=11:25;
x3=22:36;
x4=11111:11125;
y1=polyval(polyfit(x1,y,3),x1);
y2=polyval(polyfit(x2,y,3),x2);
y3=polyval(polyfit(x3,y,3),x3);
댓글 수: 2
xu
2011년 10월 10일
Walter Roberson
2011년 10월 10일
No, you are not right.
x^14 will have a precision at least 14 bits less than x itself will. You get big errors when you create a 14 degree polynomial for a non-trivial range. You would get higher precision if you created the horner version of the polynomial.
What might be *algebraically* true really doesn't matter, because real floating point arithmetic does not obey the rules of algebra. In floating point arithmetic, there are _many_ values x such that (1+x)-1 evaluates to 0. For example, (1 + 1E-100)-1 is *not* going to be 1E-100.
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!