基于有限差分法求解的二维谐振子的MATLAB程序如下。哪位大神能帮我做个注明啊,完全看不懂啊,,急0
____丿呆呆丶2017.04.15浏览20次分享举报
tic clc clear L=20; W=20; N=20; M=20; hx=L/(2*N); hy=W/(2*M); S=zeros((2*M-1)*(2*N-1)); for m=1:2*M-1 D(m,m)=-1/(hy.^2); end for m=1:2*N-2 mx=(2*M-1)*(m-1)+1; my=(2*M-1)*(m... tic
clc
clear
L=20;
W=20;
N=20;
M=20;
hx=L/(2*N);
hy=W/(2*M);
S=zeros((2*M-1)*(2*N-1));
for m=1:2*M-1
D(m,m)=-1/(hy.^2);
end
for m=1:2*N-2
mx=(2*M-1)*(m-1)+1;
my=(2*M-1)*(m-1)+2*M-1;
nx=(2*M-1)*(m-1)+(2*M-1)+1;
ny=(2*M-1)*(m-1)+2*(2*M-1);
S(mx:my,nx:ny)=D;
S(nx:ny,mx:my)=D;
end
for n=1:2*N-1
C=zeros(2*M-1);
for m=1:2*M-1
C(m,m)=2*(1/hx^2+1/hy^2)+((n-M)*hx)^2+((m-N)*hy)^2;
end
for m=1:2*M-2
C(m,m+1)=-1/hx.^2;
C(m+1,m)=-1/hx.^2;
end
cx=(2*M-1)*(n-1)+1;
cy=(2*M-1)*(n-1)+2*M-1;
S(cx:cy,cx:cy)=C;
end
[V,E]=eig(S); Y=V(:,2); k=1;
for j=1:2*M-1;
for i=1:2*N-1;
ZZ(i,j)=Y(k);
k=k+1;
end
end
y=linspace(-W/2,W/2,2*N-1);
x=linspace(-L/2,L/2,2*M-1);
[x1,y1]=meshgrid(x,y);
surf(x1,y1,-ZZ);
shading interp;
zlabel('¦•');
toc 展开