MATLAB help, LaGrange interpolation.
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?
0
Comments
a) doesn't give the right answer
b) gives errors
c) other
Doesnt give the right answers.
it says :
??? function P = pollly(N,x,y,input)
|
Error: Function definitions are not permitted at the prompt or in scripts.
plzzzz suggest another code if this is not valid
The code in the first post didn't work for the first guy...