MATLAB help, LaGrange interpolation.

edited August 2007 in Science & Tech
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?

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited May 2006
    doesn't work as in:

    a) doesn't give the right answer
    b) gives errors
    c) other
  • edited May 2006
    shwaip wrote:
    doesn't work as in:

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

    Doesnt give the right answers.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited May 2006
    I found several examples by searching google for matlab lagrange interpolation. perhaps you could try one of those.
  • edited August 2007
    shwaip wrote:
    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
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited August 2007
    what are you trying to do?

    The code in the first post didn't work for the first guy...
Sign In or Register to comment.