function FDTD_standingwave
L=2;density=1.21;speed=300;%频率300Hz、波长1米,计算两个波长
dh=0.05;%选取位置步长为0.02m
dt=0.00005;%the timestep , considering the Courant stability c*dt/dh<=1/2
nx=length(0:0.05)-1;%nx and ny are the total steps of length and width
ux(1:nx+1)=0;%设定u和p相差半个时间步长,即此时刻设定的u是u(t= -0.5)的值,而p设定的是p(t=0)时刻的值
p(1:nx)=0;
for t=1:400;
p(1)=p(1)+100*cos(2*pi*300*(t-1)*dt);%声源大小为:100*cos(2*pi*300*(t-1)*dt)简谐振动,位置在左边界点,即p(1)
for ii=1:nx;
if ii==nx;
ux(ii+1)=0;%左边界固定为0
else
ux(ii+1)=ux(ii+1)-dt/(density*dh)*(p(ii+1)-p(ii));
end