MATLAB symbolic computation script

I am trying to write a script that graphs the Lagrange interpolation of a given set of points.

The following is the code, which logically seems to be correct, but it keeps throwing an error I do not understand and I am unsure how to fix it as I am unfamiliar with MATLAB's symbolic computation capabilities and syntax.

Code:

syms x

xanchor=input('x values (enter in vector form): '); %x values of interpolating points

yanchor=input('y values (enter in vector form): '); %y values of interpolating points

N=length(xanchor);

P=ones(1,N);

for i=1:N

for j=1:N

if i~=j

P(i)=P(i)*(x-xanchor(j))/(xanchor(i)-xanchor(j));

end

end

end

f=0;

for i=i:N

f=f+yanchor(i)*P(i);

end

x1=min(xanchor);

x2=max(xanchor);

x=x1:.1:x2;

plot(x,f)

hold on

scatter(xanchor, yanchor)

hold off

The error I am getting is:

??? The following error occurred converting from sym to double:

Error using ==> mupadmex

Error in MuPAD command: DOUBLE cannot convert the input expression into

a double array.

If the input expression contains a symbolic variable, use the VPA

function instead.

Error in ==> boom at 9

P(i)=P(i)*(x-xanchor(j))/(xanchor(i)-xanchor(j));

Any help is greatly appreciated.