Find the value of interpolation polynomial
6 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(1 个)
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)
And don't forget about "What is the value of interpolation polynomial in x = 1?"
polyval(p,1)
% 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')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!