Azzera filtri
Azzera filtri

how to approximate a function using Lagrange Interpolation?

3 visualizzazioni (ultimi 30 giorni)
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!

Risposte (0)

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by