[求助]差分方法求解波动方程为什么出错了?
用差分方法求解波动方程:utt(x,t)=4ux,t), 0<x<1且0<t<0.5
边界条件为:u(0,t)=0且u(1,t)=0,0<t<0.5
u(x,0)=f(x)=x,
ut(x,0)=g(x)=0
程序如下,小弟是学习MATLAB新手,为什么出错,请高手指教啊!急盼!!!
a=1;
b=0.5;
c=1;
n=11;
m=11;
h=a/(n-1);
k=b/(m-1);
r=c*k/h;
r2=r^2;
r22=r^2/2;
s1=1-r^2;
s2=2-2*r^2;
U=zeros(n,m);
for j=1:m
U(1,j)=0;
U(n,j)=0;
end
for i=2:n-1
U(i,1)=h*(i-1);
U(i,2)=s1*h*(i-1)+r22*h*i+h*(i-2);
end
for j=3:m
for i=2n-1)
U(i,j)=s2*U(i,j-1)+r2*(U(i-1,j-1)+(U(i+1,j-1))-U(i,j-2);
end
end
U=U';