how to approximate a function using Lagrange Interpolation?
4 次查看(过去 30 天)
显示 更早的评论
Hi All,
I got an important question. It's desired to approximate the function f(x)=(x+sin(3*x))*(exp((-x^2)/4)) for the interval [-5 5].
It's a task and it's mandatory to approximate this function by Constructing a 25'th degree Lagrange polynomial. Using equally spaced data points is also required. The x-values of the first and last data points must be -5 and 5 respectively.
Here is the code:
That's the lagrange interpolation(I've written it myself):
function y = polyinterp(xNodes,yNodes,x)
n = length(xNodes);
y = zeros(size(x));
for k = 1:25
w = ones(size(x));
for j = [1:k-1 k+1:25]
w = (x-xNodes(j))./(xNodes(k)-xNodes(j)).*w;
end
y = y + w*yNodes(k);
end
and how can I use this code to construct a 25'th degree interpolating polynomial?
I'll appreciate for any help.
Thanks Already!
0 个评论
回答(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!