PDA

View Full Version : MATLAB help, LaGrange interpolation.


hallaballooo
1 May 2006, 05:38 AM
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?

shwaip
1 May 2006, 06:09 AM
doesn't work as in:

a) doesn't give the right answer
b) gives errors
c) other

hallaballooo
1 May 2006, 10:44 PM
doesn't work as in:

a) doesn't give the right answer
b) gives errors
c) other

Doesnt give the right answers.

shwaip
3 May 2006, 10:53 PM
I found several examples by searching google for matlab lagrange interpolation. perhaps you could try one of those.

sedo0o
10 Aug 2007, 09:40 PM
doesn't work as in:

a) doesn't give the right answer
b) gives errors
c) other


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

shwaip
10 Aug 2007, 10:05 PM
what are you trying to do?

The code in the first post didn't work for the first guy...