Physics with Mathematica

Eleventh Class

Make progress on your homework problems!

Animation: Just another form of Manipulate

Remove["Global`*"]

A simple example: Standing wave

Animate[
Plot[Sin[4 Pi x]Cos[2 Pi t]/.t->time,{x,0,1},
PlotRange->{-1,1}],
{time,0,5},AnimationRunning->False]

A nicer example: Traveling waves give standing waves

trainR=Sin[Pi(x-v t)/2]UnitBox[(x-v t)/width];
trainL=Sin[Pi(x+v t)/2]UnitBox[(x+v t)/width];
trains=trainR+trainL;

v=1;
end=35;
width=20;
tend=(end-0.6 width)/v;

Animate[
Plot[ trains/.t->time,{x,-end,end},
PlotRange->{{-end,end},{-2,2}}],
{time,-tend,tend},AnimationRunning->False]

Drawing geometric shapes

Remove["Global`*"]

Remember that “Plot”, etc, produce graphics as output. But there are other kinds of graphics output!

Graphics[Line[{{-1,-0.5},{1,0.5}}]]

Graphics[Circle[{0,0},1]]

len=1.25;
Show[
Plot[0,{x,-len,len},PlotRange->{-len,len},AspectRatio->1],
Graphics[Line[{{-1,-0.5},{1,0.5}}]],
Graphics[{EdgeForm[{Thick,Blue}],Circle[{0,0},1]}]]

Closed figures (nb “Circle” is not one of them) have other options

Graphics[Disk[]]

Graphics[{EdgeForm[{Thick,Blue}],FaceForm[Pink],Disk[]}]

points={{-1,0},{-0.3,1},{0.3,1},{1,0}};
trapz=Polygon[points];
Graphics[trapz]
Graphics[{Orange,trapz}]
Graphics[{EdgeForm[Thick],White,trapz}]

Physics animation with shapes: The Pendulum

Remove["Global`*"]

Use NDSolve to get the true motion of a pendulum, and use the motion to create an animation with shapes.

ϕ0=10Pi/100;
tMax=10;
eqn=ϕ''[t]+(2 Pi)^2Sin[ϕ[t]]==0;
sol=NDSolve[
{eqn,ϕ[0]==ϕ0,ϕ'[0]==0},ϕ,{t,0,tMax}];

len=1;
rBob=0.05 len;
xBob=len Sin[ϕ[t]]/.sol;
yBob=-len Cos[ϕ[t]]/.sol;
pBob={xBob[[1]],yBob[[1]]};

Animate[Show[
Plot[0,{x,-len,len},AspectRatio->1],
Graphics[{Thick,Line[{{0,0},pBob/.t->time}]}],
Graphics[{Black,Disk[pBob/.t->time,rBob]}]],
{time,0,tMax},
AnimationRate->0.5,
AnimationRunning->False]