278 CHAPTER 7. CALCULUS OF VARIATIONS
In this simulation, the proton is traveling at about 8/10 the (vacuum) speed
of light, and its mass is about 5/3 times its rest mass. eq4 , eq5 ,andeq6 are
expressed with the numerical values substituted, their outputs suppressed here.
>
eq4:=evalf(eq4); eq5:=evalf(eq5); eq6:=evalf(eq6);
The three ODES are numerically solved in sol subject to the initial condition,
>
sol:=dsolve({eq4,eq5,eq6,ic},{r(t),theta(t),phi(t)},
type=numeric,output=listprocedure):
and r(t), θ(t), φ(t) evaluated at arbitrary time t in R, Theta,andPhi.
>
R:=eval(r(t),sol): Theta:=eval(theta(t),sol):
Phi:=eval(phi(t),sol):
For plotting purposes, three functional operators are now introduced to convert
from spherical polar coordinates to Cartesian coordinates at arbitrary time t.
>
x:=t->R(t)*sin(Theta(t))*cos(Phi(t)):
>
y:=t->R(t)*sin(Theta(t))*sin(Phi(t)):
>
z:=t->R(t)*cos(Theta(t)):
The total time (tt) for the animation is taken to be 3.5 seconds, N = 100 frames
will be used, and the time step will be tt/N .
>
tt:=3.5: N:=100: step:=tt/N:
In gr1,thespacecurve command is used to plot the proton’s trajectory from
t =0 to t = tt. The coordinates x(t), y(t), and z(t) are normalized by dividing
by the radius RE of the earth. The trajectory is colored with the zhue option.
>
gr1:=spacecurve([x(t)/RE,y(t)/RE,z(t)/RE],t=0..tt,
numpoints=2000,shading=zhue):
In gr2,theplot3d command is used in spherical coordinates to plot a bluish
colored sphere of radius 1 to represent the earth.
>
gr2:=plot3d(1,theta=0..Pi,phi=0..2*Pi,coords=spherical,
color=COLOR(RGB,0.1,0.5,0.8),style=patchnogrid):
In the following do loop, the proton’s position is plotted at each time step and
superimposed on the graphs gr1 and gr2.
>
fornfrom0toNdo
>
t:=step*n;
>
gr3||n:=pointplot3d([x(t)/RE,y(t)/RE,z(t)/RE],style=point,
symbol=circle,symbolsize=16,color=red);
>
pl||n:=display({gr1,gr2,gr3||n});
>
end do:
Using the display command with the insequence=true option allows the pro-
ton’s motion to be animated.
>
display(seq(pl||n,n=0..N),insequence=true,
scaling=constrained,axes=framed,labels=["x","y","z"],
orientation=[45,55],tickmarks=[3,3,3]);
On executing the last command line and clicking on the computer plot and on