hallaballooo
1 May 2006, 5:38am
Does anyone know how to write a matlab program to compute lagrange interpolation? I have a set of data and I want to estimate the value of the data between points using LaGrange. I put this code together:
function P = pollly(N,x,y,input)
N = N+1;
X = 0;
for j = 1:N
X = X + y(j) * lagrange(N,j,x,input);
end
P = X;
function L = lagrange(N,j,x,guess)
L = 1;
for i = 1:N
if (i ~= j)
L = L * ( guess - x(i) ) / ( x(j) - x(i) );
end
end
But it doesnt work at all. Can someone please help?
function P = pollly(N,x,y,input)
N = N+1;
X = 0;
for j = 1:N
X = X + y(j) * lagrange(N,j,x,input);
end
P = X;
function L = lagrange(N,j,x,guess)
L = 1;
for i = 1:N
if (i ~= j)
L = L * ( guess - x(i) ) / ( x(j) - x(i) );
end
end
But it doesnt work at all. Can someone please help?