Find the value of interpolation polynomial

조회 수: 6 (최근 30일)
Nikodin Sedlarevic
Nikodin Sedlarevic 2022년 5월 15일
답변: Voss 2022년 5월 15일
On the interval [−2,2] I have the given function f (x) = (8 *a^3) / (x^2 + 4*a^2), where is parameter a = 1 / 2.80. I would like to approximate the function by interpolation polynomial. Use the polyfit command to find the interpolation polynomial written in standard base interpolating f in x = −2,0,2. What is the value of interpolation polynomial in x = 1?
Is this alright or I have to change something?
format long
a = 1./2.80;
f = @(x) (8.*a.^3)./(x.^2+4.*a.^2);
p = polyfit(-2:2,f(-2:2),2)
p = 1×3
-0.113427907545555 0.000000000000000 0.498558675029263

답변 (1개)

Voss
Voss 2022년 5월 15일
"interpolating f in x = −2,0,2"
To me that sounds like you should use f(x) at x = -2, 0, and 2, rather than x = -2:2, which is x = -2, -1, 0, 1, and 2.
format long
a = 1./2.80;
f = @(x) (8.*a.^3)./(x.^2+4.*a.^2);
p = polyfit([-2 0 2],f([-2 0 2]),2)
p = 1×3
-0.158371040723982 0 0.714285714285714
And don't forget about "What is the value of interpolation polynomial in x = 1?"
polyval(p,1)
ans =
0.555914673561732
% visual aid:
% rational function f:
plot(-2:0.01:2,f(-2:0.01:2))
hold on
% polynomial fit from x = [-2 0 2]:
plot(-2:0.01:2,polyval(p,-2:0.01:2),'--r')
% also plot the polynomial fit from x = [-2 -1 0 1 2], for reference:
p_old = polyfit(-2:2,f(-2:2),2);
plot(-2:0.01:2,polyval(p_old,-2:0.01:2),':m')

카테고리

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