Physics with Mathematica

Twelfth Class

This has been fun. I will miss this class. Don’t forget to hand in your homework assignments!

We have only scratched the surface of options for Plot

Remove["Global`*"]

For example, a fancy demonstration plot of Bessel Functions

Plot[Evaluate[Table[BesselJ[n,x],{n,4}]],{x,0,10},Filling->Axis,PlotLabel->Bessel Functions,LabelStyle->{25,Purple}]

Plotting in three dimensions

Φ=Sqrt[x^2+y^2];
v=(Φ^2-a^2)^2;
a=1;xylim=1.2 a;
Plot3D[v,{x,-xylim,xylim},{y,-xylim,xylim}]

d=3;
Manipulate[Plot3D[v,{x,-xylim,xylim},{y,-xylim,xylim},ViewPoint->{d Cos[ϕ] Sin[θ],d Sin[ϕ] Sin[θ],d Cos[θ]}],{ϕ,0,2 Pi},{θ,0,Pi}]

Interlude: Vector calculus

Remove["Global`*"]

Gradient, Divergence, and Curl are all available to you

Φ=x^2+y^2;
Grad[Φ,{x,y}]

v=1/Sqrt[x^2+y^2+z^2];
e=Grad[v,{x,y,z}]

Div[e,{x,y,z}]

Simplify[%]

I’m not sure why this last operation isn’t conditional so that (x,y,z) is not (0,0,0).

Plotting scalar and vector fields

Remove["Global`*"]

Contour plots for scalar fields

Φ=Sqrt[x^2+y^2];
v=(Φ^2-a^2)^2;
a=1;xylim=1.2 a;
ContourPlot[v,{x,-xylim,xylim},{y,-xylim,xylim}]

ContourPlot[v,{x,-xylim,xylim},{y,-xylim,xylim},
ContourShading->None,ContourLabels->True,Contours->{0.1,0.5,0.85}]

Stream plots for vector fields

w=Grad[v,{x,y}];
StreamPlot[w,{x,-xylim,xylim},{y,-xylim,xylim}]

Vector plots for vector fields have more information, but are hard to use for fields with lots of variation in magnitude

VectorPlot[w,{x,-xylim,xylim},{y,-xylim,xylim}]

f=0.75;
VectorPlot[w,{x,-f xylim,f xylim},{y,-f xylim,f xylim}]