16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Using the operator F, we add the three time-dependent solitary waves in f, and<br />

take the time derivative of f in g.<br />

> f:= add(F(X[i],c[i]),i=1..3): g:=diff(f,t):<br />

Setting the time to zero, we plot the input pro¯le over the spatial range x =0<br />

to M, the resulting picture being shown in Figure 7.8.<br />

> t:=0: plot(f,x=0..M,thickness=2);<br />

2.5<br />

2<br />

1.5<br />

1<br />

0.5<br />

0 50 100 x 150 200 250<br />

Figure 7.8: Input pro¯le for the three-solitary-wave collision simulation.<br />

Note that there is a slight overlap of the solitary-wave tails. One could place<br />

them further apart initially, but this takes more computing time.<br />

To evaluate f and g at the spatial mesh points, we use the unapply command<br />

to turn them into operators in terms of the spatial coordinate x.<br />

> f2:=unapply(f,x): g2:=unapply(g,x):<br />

Using these two operators, we calculate the input amplitudes Ui;0 ´ f(i; t =0)<br />

and Ui;1 ´ f(i; t =0)+kg(i; t =0)fori =0toM in the ¯rst and second<br />

initial conditions, ic1 and ic2 .<br />

> ic1:=seq(U(i,0)=evalf(f2(i)),i=0..M):<br />

> ic2:=seq(U(i,1)=evalf(f2(i))+k*g2(i),i=0..M):<br />

To avoid any possible unknown U values creeping into the double do loop that<br />

will be used to iterate the numerical algorithm, we \initialize" all U values to<br />

zero for i =0toM and j =2toN, i.e., for all remaining grid points. These<br />

zeros will be overwritten as the loop is executed and new U values calculated.<br />

> init:=seq(seq(U(i,j)=0,i=0..M),j=2..N):<br />

The two initial conditions and the initialization are assigned.<br />

> assign(ic1,ic2,init):

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

Saved successfully!

Ooh no, something went wrong!