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.

178 CHAPTER 4. NONLINEAR ODE MODELS<br />

x(0) = 0:5, y(0) = 0, z(0) = 0, _x(0) = 0, _y(0) = ¡2, and _z(0) = ¡0:2.<br />

> m:=1: q:=1:<br />

> ic:=(x(0)=0.5,y(0)=0,z(0)=0,D(x)(0)=0,D(y)(0)=-2,D(z)(0)=0.2):<br />

Maple is not able to produce an explicit closed-form analytic solution for the<br />

nonlinear ODE system, sys, so a numerical solution is generated, the output<br />

being given as a \listprocedure."<br />

> sol:=dsolve(fsys,icg,fx(t),y(t),z(t)g,numeric,<br />

output=listprocedure):<br />

Evaluating x(t), y(t), and z(t) withsol will allow Vectoria to calculate the<br />

charge's position at an arbitrary time t.<br />

> X:=eval(x(t),sol): Y:=eval(y(t),sol): Z:=eval(z(t),sol):<br />

For example, the charge's x-coordinate at t = 2 time units is now evaluated.<br />

> X(2);<br />

¡0:0727500262205896948<br />

Vectoria will now animate the motion of the charge in the magnetic bottle. She<br />

takes the total time to be T =24:0time units and will have N =200time<br />

steps in her animation. The time step size T=N is then calculated.<br />

> T:=24.0: N:=200: step:=T/N;<br />

step := 0:1200000000<br />

The spacecurve command is used to plot (but not display) the entire trajectory<br />

overthetimeintervalt =0toT , the trajectory being colored with the zhue<br />

option. To obtain a smooth curve, the minimum number of plotting points is<br />

taken to be 1000.<br />

> sc:=spacecurve([X(t),Y(t),Z(t)],t=0..T,shading=zhue,<br />

numpoints=1000):<br />

Using a do loop running from n =0toN, the charge is plotted on each time step<br />

in 3 dimensions as a size-18 red circle superimposed on the entire trajectory.<br />

> for n from 0 to N do<br />

> t:=step*n;<br />

> pp[n]:=pointplot3d([X(t),Y(t),Z(t)],symbol=circle,<br />

symbolsize=18,color=red);<br />

> gr[n]:=display(fsc,pp[n]g);<br />

> end do:<br />

The motion of the charge in the magnetic bottle is animated with the display<br />

command, using the insequence=true option. To see the animation execute<br />

the worksheet, click on the plot, and on the start arrow in the tool bar.<br />

> display(seq(gr[n],n=0..N),insequence=true,axes=frame,<br />

labels=["x","y","z"]);<br />

Vectoria is quite pleased that her piecewise model mimics magnetic bottle behavior.<br />

But now she has to forsake this bottle for another one, as she rushes<br />

o® to join her girlfriends and share a bottle of Asti Spumante.

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

Saved successfully!

Ooh no, something went wrong!