Hurrdof
Hurrdof

Reputation: 23

I can't find how to solve this parse error

I was writing a Lagrange interpolation algorithm but my code keeps signaling me a parse error about my "endif"

function g=lagrange(x,y,a)
  g=0
  n=length(x)
for j = 0:n
  if j~=i
    v=v*((a-x(i))/(x(j)-x(i))
  end
   g=g+v*y(j)
  endfor
endfunction 

and even if I try with a simple "end", it says


  syntax error

>>>   endif
          ^

>> lagrange

parse error near line 7 of file C:\Users\Victor\Desktop\octave\lagrange.m

  syntax error

>>>   end
        ^

Upvotes: 1

Views: 1654

Answers (1)

Andrew Janke
Andrew Janke

Reputation: 23858

This line:

v=v*((a-x(i))/(x(j)-x(i))

Has more open parentheses than close parentheses. Fix that and your syntax error should go away.

Upvotes: 1

Related Questions