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 个)

类别

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