MATLAB: Index in position 1 is invalid but I need w(0,j), w(0,0), and w(m,0)

equationequationserrormathmathematicsMATLABsolvingwave equation

I am following an algorithm for wave equations (shown on the pic). I get the error "Index in position 1 is invalid. Array indices must be positive integers or logical values." What do I do, if w(0,j), w(0,0), and w(m,0) are needed? Also, in this line "wij(i,1)=(1-lambda^2)*f(i*h)+(lambda^2/2)*(f((i+1)*h)+f((i-1)*h))+k*g(i*h);" i get the error "Unable to convert expression containing symbolic variables into double array." Help would be very much appreciated, thanks.
This is my program:
%STEP0
l=1; %endpoint
T=1; %maximum time
alpha = 2; %constant
m=10;
N=20;
syms f(x) g(x,t)
f(x)=sin(pi*x);
g(x)=(sin(pi*x))*(cos(2*pi*t));
%STEP1
h=l/m;
k=T/N;
lambda=k*alpha/h;
%STEP2
for j=1:N
wij(0,j)=0;
wij(m,j)=0;
end
%STEP3
wi(0,0)=f(0);
wi(m,0)=f(l);
%STEP4
for i=1:m-1
wij(i,0)=f(i*h);
wij(i,1)=(1-lambda^2)*f(i*h)+(lambda^2/2)*(f((i+1)*h)+f((i-1)*h))+k*g(i*h);
end
%STEP5
for j=1:N-1
for i=1:m-1
wij(i,j+1)=2*(1-lambda^2)*w(i,j)+lambda^2*(wij(i+1,j)+wij(i-1,j))-wij(i,j-1);
end
end
%STEP6
for j=0:N
t=j*k;
for i=0:m
x-i*h;
fprintf( '%.1f %.1f %.10f',x,t,wij(i,j))
end
end

Best Answer

I'm pretty sure the answer here is that unlike most other languages, MATLAB starts indexing at 1, not 0. So for example in the code you wrote:
%STEP 2
for j=1:N
wij(1,j)=0;
wij(m,j)=0;
end
would give the desired result - you would then have to change the others to have an index of 1 instead of 0.