16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

316 CHAPTER 7. THE HUNT FOR SOLITONS<br />

The kink is on the left, the antikink on the right, the two pro¯les being joined<br />

together in the middle. At the x boundaries, one has U ¼ 2 ¼ and @U=@x ¼ 0.<br />

Since the kink is traveling to the right and the antikink to the left, a collision will<br />

take place before each reaches the opposite boundary. Provided that we do not<br />

let the kink and antikink come close to those boundaries, the above boundary<br />

conditions will prevail for all times in the run. This implies that @U=@t ¼ 0at<br />

the x boundaries. In the following do loop, the x-boundary grid points (circled<br />

points in Figure 7.9) are initialized, setting U =2¼ and p = q =0.<br />

> for j from 2 to N by 2 do #boundary conditions<br />

> u[0,j]:=2*evalf(Pi): p[0,j]:=0: q[0,j]:=0;<br />

> u[M,j]:=2*evalf(Pi): p[M,j]:=0: q[M,j]:=0;<br />

> end do:<br />

The following double do loop calculates the values of u at the other grid points.<br />

> for j from 0 to (N-1) do:<br />

A conditional statement is inserted to start i at i0 =0forj =0; 2; 4; ::: and<br />

i0 =1forj =1; 3; 5; ::::<br />

> if j mod 2 = 0 then i0:=0: else i0:=1: end if;<br />

The following do loop runs over the spatial grid points i, incrementing them<br />

from i0 to M ¡ 2instepsof2.<br />

> for i from i0 to (M-2) by 2 do<br />

Using equation (7.15), we calculate the values of p and q.<br />

> p[i+1,j+1]:=0.5*(p[i+2,j]+p[i,j]+q[i+2,j]-q[i,j]<br />

+(-sin(u[i+2,j])+sin(u[i,j]))*h);<br />

> q[i+1,j+1]:=0.5*(p[i+2,j]-p[i,j]+q[i+2,j]+q[i,j]<br />

+(-sin(u[i+2,j])-sin(u[i,j]))*h);<br />

Then U is evaluated using equations (7.16) and (7.17), and the average taken.<br />

> uP1:=u[i,j]+0.5*h*(p[i,j]+p[i+1,j+1] +q[i,j]+q[i+1,j+1]);<br />

> uP2:=u[i+2,j]+0.5*h*(-p[i+2,j]-p[i+1,j+1]+q[i+2,j]<br />

+q[i+1,j+1]);<br />

> u[i+1,j+1]:=(uP1+uP2)/2;<br />

> end do: end do:<br />

The results are plotted,<br />

> for j from 0 to N by 2 do<br />

> pl(j):=plot([seq([xmin+2*i*h,u[2*i,j]],i=0..M/2)],<br />

thickness=3,labels=["x","U"]):<br />

> end do:<br />

andanimatedwiththeinsequence=true option.<br />

> plots[display]([seq(pl(2*j),j=0..N/2)],insequence=true);<br />

When the work sheet is executed, the kink{antikink hump °ips upside down<br />

but the shape of the moving pro¯le is identical to the input shape aside from a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!