## a script for a sound wave source made up of two different masses ##seperated in the middle. Let the rigth part is lighter than the
##left one that ensures that the ligther is faster, and so has
##greater r since r=cdt/dx which is dimensionless(ratio).
dx=1e-2; ## Increment in the horizontal distance (m)
c1=300; ## speed of the left one (m/s)
c2=500; ## Speed of the rigth one (m/s)
dt=dx/max(c1,c2); ## Increment in time (s). The max c, the min dt.
r1=c1*dt/dx; ## Ratio r for the left one
r2=c2*dt/dx; ## Ration r for the right one
x=-1:dx:1; ## same as the string_fixed
l=length(x);
x0=0.5;
k=1e2;
## Inital profile(return to guassuian distibution)
y=initial_profile(x,x0,k);
axis([-1.05,1.05,-1.1,1.1])
plot(x,y,'r;;',[0 0],[-1.1 1.1],'r-;;')
pause
## Boundary conditions while t=dtn=0
ynow=y;
yprev=y;
N=100;
for n=1:N
ynext=propagate_two_parts(ynow,yprev,r1,r2); ## calling the prepared
## function
plot(x,ynext,';;',[0 0],[-1.1 1.1],'r-;;')
axis([-1.05,1.05,-1.1,1.1])
pause(0);
yprev=ynow;
ynow=ynext;
endfor
Comments
Post a Comment