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.

7.3. SIMULATING SOLITON COLLISIONS 311<br />

An operator G is introduced to calculate the rhs of the Zabusky{Kruskal algorithm<br />

(7.6) (with à replaced with U) for a speci¯ed i and j.<br />

> G:=(i,j)->U(i,j-1)-r*h^2*(U(i+1,j)+U(i,j)+U(i-1,j))<br />

*(U(i+1,j)-U(i-1,j))/3<br />

-r*(U(i+2,j)-2*U(i+1,j)+2*U(i-1,j)-U(i-2,j)):<br />

The numerical algorithm is ¯rst iterated from i =2toM ¡ 2foragivenjvalue and then from j =1toN. The spatial index i isstartedat2andendedat<br />

M ¡ 2 to avoid unknown U values from the two edges of the grid entering into<br />

the double do loop calculation.<br />

> for j from 1 to N do;<br />

> for i from 2 to M-2 do<br />

> U(i,j+1):=G(i,j):<br />

> end do:<br />

> end do:<br />

A graphing operator is formed to plot the entire pro¯le on the jth time step.<br />

> gr:=j->plot([seq([i,U(i,j)],i=2..M-2)],thickness=2):<br />

Using every second graph, the sequence of pictures is now animated.<br />

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

You will have to execute the recipe, click on the resulting plot, and then on the<br />

start arrow to see the wonderful animation. Despite the initial overlap of the<br />

solitary-wave tails and the coarse spatial grid used (recall, h = 1), the solitary<br />

waves are remarkably stable, all three surviving the collision process apparently<br />

unchanged. After the collision the order of the waves is the reverse of the initial<br />

ordering, with the smallest pulse on the left and the largest on the right.<br />

> cpu:=time()-begin;<br />

cpu := 29:072<br />

The CPU time on a 3-GHz PC is about 29 seconds.<br />

Although we have concentrated on soliton collisions here, the recipe may<br />

be easily modi¯ed to investigate the behavior of other input pro¯les. For most<br />

cases, an analytic solution will not exist and the numerical simulation route is<br />

the only feasible one to take.<br />

PROBLEMS:<br />

Problem 7-17: Third derivative<br />

Using the Taylor expansion, derive the approximation (7.5) to @3Ã=@3x. Problem 7-18: A di®erent scheme<br />

In the Zabusky{Kruskal ¯nite di®erence scheme for the KdV equation, Ã in the<br />

nonlinear term à (@Ã=@x) was approximated by the average of three à terms<br />

at the grid points (i +1;j), (i; j), and (i ¡ 1;j). Compare the results obtained<br />

in the text recipe with those you would obtain if U ´ Ã were approximated by<br />

Ui;j alone. Discuss your result.

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

Saved successfully!

Ooh no, something went wrong!