
9.2. PARTIAL DIFFERENTIAL EQUATIONS 367
The leading edge of each pulse will just make contact in N = M/2 = 60 time
steps. If we let i and j index the x and y steps, as in Figure 9.14, the grid
coordinates for j =0, 2, ... are (0,j), (2,j), (4,j), ..., while for j =1, 3, ... they
are (1,j), (3,j), (5,j), ... For later convenience, we set m=2i and n =2j.
>
restart: with(plots): begin:=time():
>
L:=1: M:=120: h:=L/M; N:=M/2; m:=2*i: n:=2*j:
h :=
1
120
N := 60
Thevaluesofg
1
, g
2
,andb are entered. A functional operator S is introduced
to calculate the input laser shape on the boundaries.
>
g1:=0.4; g2:=20; b:=0.5; S:=j->sin(n*evalf(Pi)/N);
g1 := 0.4 g2 := 20 b := 0.5 S := j → sin(
n evalf(π)
N
)
Using S, the boundary conditions are applied at i=0 and M in bc1 and bc2.
>
bc1:=seq(u[0,n]=S(j),j=0..N/2),seq(u[0,n]=0,j=N/2+1..3*N):
>
bc2:=seq(v[M,n]=S(j),j=0..N/2),seq(v[M,n]=0,j=N/2+1..3*N):
The initial condition is entered and assigned along with bc1 and bc2.
>
ic:=seq(u[m,0]=0,i=0..M/2),seq(v[m,0]=0,i=0..M/2):
>
assign(bc1,bc2,ic):
Functional operators are formed to evaluate f
1
and f
2
for a given i, j.
>
f1:=(i,j)->-g1*u[i,j]*v[i,j]-b*u[i,j]:
f2:=(i,j)->-g2*u[i,j]*v[i,j]+b*v[i,j]:
A double do loop is used to iterate (9.29). The conditional if...then statement
is included so that i starts at i0=0 for j =0, 2, 4, ... and i0=1 for j =1, 3, ....
>
for j from 0 to 3*N do
>
if j mod 2 = 0 then i0: = 0 else i0:=1 end if;
>
for i from i0 to M by 2 do
>
u[i+1,j+1]: = u[i,j]+h*f1(i,j);
>
v[i-1,j+1]: = v[i,j]-h*f2(i,j);
>
end do: end do:
An operator gr is formed to plot u and v on the jth time step.
>
gr:=j->plot([[seq([m*h,u[m,n]],i=0..M/2)],[seq([m*h,v[m,n]],
i=0..M/2)]],color=[red,blue],labels=["x","u,v"],thickness=2):
The numerically obtained profiles are animated with the display command
with the insequence=true option. Click on the computer plot and the start
arrow to initiate the animation.
>
display([seq(gr(j),j=0..2*N)],insequence=true);
The cpu time for the entire recipe is given below.
>
cpu:=time()-begin;
cpu := 7.752