Reflections on Teaching Computational Physics and Applied Mathematics

Paul Abbott
School of Physics
The University of Western Australia

paul.c.abbott@uwa.edu.au

Join the Conversation #WolframTechConf

Introduction

Usual Approach

In most applied mathematics and computational physics courses, simulation and modelling are taught by stressing numerical techniques, while visualisation often requires a range of specialised software tools:

Standard texts teach computation by having students develop or edit procedural code fragments to model a particular physical problem or system.

This approach requires the understanding of many details of a procedural programming language such as Fortran or C.

Although learning procedural programming is very useful it detracts from the desired goal of teaching exploration.

Black Box Approach

A second approach is to develop custom “black-box” applications for illustrating specific mathematical or physical concepts:

When well done—as is the case with many Demonstrations—this approach has the advantage that such applications can be used with little instruction, and the focus is entirely on the situation under investigation.

A disadvantage is that the student may not learn any computational techniques, though reading the source code for Demonstrations can be enlightening.

Immersive Approach

The third way is to use an integrated computational environment.

Mathematica has revolutionised the teaching and learning in a range of computational disciplines because it has an excellent graphical user interface (GUI) and provides a unified environment for symbolic and numeric computation, combined with a high-level programming language.

I have chosen to use the third approach in all my teaching over the last 25 years.

Over this time, and with each successive release, Mathematica has improved to the point that makes it an indispensable tool for all students.

In this talk I will demonstrate my approach by showing examples taken from lectures, assignments, and exams.

My Background

Physicist

Used computer algebra systems [CAS] in teaching (and research) since 1980 (Reduce, Macsyma, Maple, SMP, Mathematica)

Taught physics and mathematics to science and engineering students since 1985

Australian National Teaching Development grant with Des Fearnley-Sander (University of Tasmania) on Teaching and Learning Calculus and its Applications with Mathematica

2016 Australian University Teaching Award: Citation for Outstanding Contribution to Student Learning

Which Tool to use in Teaching?

Wide choice of tools: MathCAD, Matlab, Maple, Mathematica, GeoGebra, Fortran, C, Java, …

Mathematica must compete with other teaching technologies

Most people stick with the tool(s) that they know best

How to integrate technology into teaching in a non-trivial way?

Why use Mathematica?

Integration of symbolic and numeric computation

Consistency checking—numeric and symbolic

If only teaching one tool, teach the most generic

Choose the best tool for exploration

One can use mathematical notation and add new notations

Introduction

The White-Box/Black-Box principle

Buchberger (1990)

Proposed White-Box/Black-Box principle (WBBB) to describe learning with a CAS:

In the stage where area X is new to the students, the use of a symbolic software system realizing the algorithm of area X as black boxes would be a disaster. Students have to study the area thoroughly, that is they should study problems, basic concepts theorems, proofs, algorithms based on the theorems, examples, and hand calculations.

In the stage where area X has been thoroughly studied, when hand calculation for simple examples become routine, and hand calculations for complex problems becomes intractable, students should be allowed and encouraged to use the respective algorithms available in symbolic software systems.

Kutzler (1999)

Modified the WBBB principle: students who do not master certain topics can use CAS as a scaffolding to help understand higher level topics.

Drivers (2000)

Proposed inverting the sequence—Black-Box/White-Box—using a CAS as a generator of examples and as an explorative tool that confronts the student with new situations. The explorative Black-Box phase can lead to (directed) discoveries. In the White-Box phase the results of the explorations are examined and can lead to the development of new concepts.

Introduction

Approaches to using Mathematica in Teaching

Require students to learn to use Mathematica commands directly

Gives students experience with professional tools

Requires instructor training and dedicating time to "teach the program" to students

One (good) approach is to learn Mathematica is by “hacking”

Many CAS-based courses take traditional approaches and use standard material

Write your own demonstrations for use in class

Address topic exactly as you see fit

Once you get beyond basic usage, there are many Mathematica details you need to know.

Modifying existing examples is a good way to simplify this task.

Use pre-written demonstrations in class

Little or no training required; sometimes possible to modify to taste

You take what you can find, even if it isn't really what you want

Problem-based Learning

My Goal

Use and teach the real power of Mathematica via problem-based learning (PBL).

Rather than presenting worked examples, students work through problems themselves.

Advantages

This approach has three main advantages:

doing the problems leads to a deeper understanding of the concepts involved

the students learn problem-solving techniques

the students learn Mathematica by “absorption”

My Approach

Mathematica is used in my courses immersively as both a presentation environment and a computational tool:

Applied Mathematics ⊳ https://wolfr.am/gynvcAWx

Computational Physics ⊳ https://wolfr.am/gynCJnJU and https://wolfr.am/gynEy7fB

Laboratory

The “hands-on” laboratory sessions consist of a set of computational experiments (worth a total of 60%). The Notebooks provide guidance through hints or suggestions along with checkpoints at major stages of each computation.

Students submit their solutions to each assignment as annotated Notebooks. Since Notebooks can include text, graphics, and sound, it is easy for students to show (graphically, numerically, symbolically, visually, …) how a solution was obtained, and to check and cross-check their results.

When marking it is easy to further annotate the student Notebook (including computational demonstrations and graphics) to explain ideas that have not been fully appreciated.

Possibility of automatic marking of student work via solution templates.

Exam

The final exam makes up the remaining 40%. The exam follows a similar format to the laboratory sessions but the amount of guidance is reduced.

Examples

Second year Applied Mathematics exam.

Third year Computational Physics exam.

Comments

This approach has a significant positive effect on student learning because:

they are learning a tool widely used by research students and scientists

Mathematica is interactive and it encourages student experimentation

Useful Resources

Developing courses from scratch is time-consuming.

Avoid re-inventing things by selecting topics from the huge range of resources:

MathWorld ⊳ http://mathworld.wolfram.com/

The Functions Site ⊳ http://functions.wolfram.com/

The NIST Digital Library of Mathematical Functions: DLMF ⊳ http://dlmf.nist.gov/

Demonstrations website ⊳ http://demonstrations.wolfram.com/

Wolfram|Alpha ⊳ http://wolframalpha.com/

Teaching Examples

Here are some selected teaching examples.

Analysis of Pulsar Timing Data

Data

Imports a data file consisting of timing residuals for the pulsar PSR1257+12

data=Import["ftp://ftp.physics.uwa.edu.au/pub/Data/pulsar.dat","Table"]

Convert the data file to a Dataset

dataset=Dataset@(Association/@Thread/@Map[{"n","year","residual","phase","error"}->##&,data])

Select columns 2 (epoch, i.e., time in decimal years) and 3 (residual in ms), subtract 1990 from all the epoch values and convert to a TimeSeries

ts=TimeSeries[data[[All,3]],{data[[All,2]]-1990}]

Residuals

Visualize the residuals

residuals=ListPlot[ts,AspectRatio->1/6,PlotStyle->{Red,AbsolutePointSize[4]}]

Spectral Analysis

There is a simple spectral analysis method that avoids interpolation and resampling: For each frequency ω, fit α and β in α sin(ω t)+β cos(ω t) to the data by linear least-squares. The spectral energy ℰ(ω) is then the square amplitude integrated over one period, T=2 π/ω (normalised by dividing by T).

The spectral energy ℰ(ω) of (α sin(ω t)+β cos(ω t)) is ℰ(ω)=(1/2) ((α^2)+(β^2)).

Compute the spectral energy ℰ(ω) using Fit and perform the required integration by pattern-matching

ℰ[ω_?NumericQ]:=Fit[ts,{Sin[ω t],Cos[ω t]},t]/. α_ Sin[t_]+β_ Cos[t_]:>(1/2) ((α^2)+(β^2))

Plot ℰ(ω) as a function of ω

Plot[ℰ[ω],{ω,1,50},PlotRange->All]

Nonlinear fit

Compute the regression for the two planet nonlinear model using nondefault starting values for the parameters

params=FindFit[ts,α Sin[t ω+ϕ]+β Sin[t Ω+δ]+ϵ,{α,β,ϕ,δ,{ω,23},{Ω,34},ϵ},t]

Verification

Check the quality of the nonlinear fit

Show[residuals,Plot[α Sin[t ω+ϕ]+β Sin[t Ω+δ]+ϵ/. params,{t,ts["FirstTime"],ts["LastTime"]}]]

Teaching Examples

Complex Functions

Gamma Function

Plot (Gamma[x+i y])==r (e^(i θ)) coloured by phase θ. Orthogonal mesh shows lines of constant r and constant θ

ComplexPlot[Γ(z),{z,-4.1-2I,4.1+2I},BoxRatios->{3,2,1}]

Zeta Function

Plot (Zeta[x+i y]) over the critical strip. The Riemann Hypothesis is that all the zeros s=(ZetaZero[k]) of (Zeta[s]) lie on the critical line Re(s)==x==1/2

ComplexPlot[(Zeta[z]),{z,-1.1+5I,2.1+50I},BoxRatios->{10,55,5},PlotRange->{0,5}]

Teaching Examples

Atomic and Molecular physics

Spherical harmonics (Subscript[Y, l]^m)(θ,φ) are the building blocks of atomic and molecular orbitals.

Plots of (real) spherical harmonics with 0≤(Abs[m])≤l≤2

GraphicsGrid[Table[SphericalPlot3D[
Evaluate[Tooltip[\[LeftBracketingBar](Subscript[Y, l]^m)(θ,φ)+(((-1))^l) sgn(m) (Subscript[Y, l]^(-m))(θ,φ)\[RightBracketingBar],Switch[l,0,"s",1,"p",2,"d"]]],
{θ,0,π},{φ,0,2 π},
PlotStyle->Directive[Orange,Opacity[0.5],Specularity[White,10]],BoxRatios->1,Mesh->False,Boxed->True,Axes->None,PlotRange->All,ImageSize->100],
{l,0,2},{m,-l,l}]]

For a more complicated atomic orbitals, such as a coherently excited F-state atom, here is the charge density

(Subscript[Ω, 3])[(({{(Subscript[a, 3]), (Subscript[b, 3])}, {(Subscript[a, 1]), 0}, {(Subscript[a, -1]), (Subscript[b, -1])}, {(Subscript[a, -3]), (Subscript[b, -3])}}))][θ,ϕ]

Visualize the F-state orbital for a range of parameters

Manipulate[SphericalPlot3D[Evaluate[(Subscript[Ω, 3])[(({{(Subscript[a, 3]), (Subscript[b, 3])}, {(Subscript[a, 1]), 0}, {(Subscript[a, -1]), (Subscript[b, -1])}, {(Subscript[a, -3]), (Subscript[b, -3])}}))][θ,ϕ]],{θ,0,π},{ϕ,0,2 π},PlotRange->1,BoxRatios->{1, 1, 1}],
{{(Subscript[a, 1]),1},0,2},{{(Subscript[a, -1]),0},0,2},{{(Subscript[a, 3]),0.8},0,2},{{(Subscript[a, -3]),0.05},0,2},{{(Subscript[b, -1]),π},0,2π},{{(Subscript[b, 3]),(π/5)},0,π},{{(Subscript[b, -3]),(π/4)},0,π},SaveDefinitions->True]

Teaching Examples

Euler Angles

Rotation Matrices

Construct a RotationMatrix for rotations about the z-axis.

RotationMatrix[ϕ,{0,0,1}]

Transformation Functions

Construct a TransformationFunction for Euler angle rotations {ϕ,θ,ψ} by composing RotationTransform operations:

euler[{ϕ_,θ_,ψ_}]=RotationTransform[ϕ,{0,0,1}]@*RotationTransform[θ,{1,0,0}]@*RotationTransform[ψ,{0,0,1}]

Euler angle rotations

Demonstrate Euler angle rotations {ϕ,θ,ψ}

Manipulate[Graphics3D[{Opacity[0.1],cylinder,Opacity[0.6],GeometricTransformation[{axes,cylinder},euler[{ϕ,θ,ψ}]],Opacity[1],Red,axes},PlotRange->1,Boxed->False,ViewCenter->{0,0,0},ViewPoint->{3,1,1},ImageSize->400,ImageMargins->0],{ϕ,0,2 π},{θ,0,π},{ψ,0,2 π},ControlPlacement->Left,Initialization:>{cylinder=Cylinder[{{0,0,-0.02},{0,0,0.02}},0.8],axes=Module[{𝒪,e},𝒪={0,0,0};Thread[{(Subscript[e, 1]),(Subscript[e, 2]),(Subscript[e, 3])}=IdentityMatrix[3]];{Arrow[{𝒪,(Subscript[e, 1])}],Text[𝒾,1.1 (Subscript[e, 1])],Arrow[{𝒪,(Subscript[e, 2])}],Text[𝒿,1.1 (Subscript[e, 2])],Arrow[{𝒪,(Subscript[e, 3])}],Text[𝓀,1.1 (Subscript[e, 3])]}]},SaveDefinitions->True]

Teaching Examples

Chemistry Electronic Laboratory Notebooks

Reaction equation

It is easy to construct a diagram of the balanced equation for the reaction of benzylamine with benzoyl chloride

ChemicalData[LinguisticAssistant]+ChemicalData[LinguisticAssistant]==ChemicalData[LinguisticAssistant]+ChemicalData[LinguisticAssistant]

Teaching Examples

Quantum Transport

A dynamic interface for displaying low-order squared Wigner-Eisenbud functions, (((Subscript[χ, l])(z))^2), shifted upwards by their eigenvalue (Subscript[E, l]), for square-well potentials of various widths and depths, in dimensionless units. A scale factor is applied to (((Subscript[χ, l])(z))^2) to improve the visualization

Manipulate[Module[{pot,wef,v,es},
pot[w_,d_]:=z|->Piecewise[{{-d,-w≤z≤w}}];
v=SampledFunction[pot[w,d],(2^n),{-1,1}];
es=First@WignerEisenbudSystem[v];
wef=WignerEisenbudFunctions[v];
Show[
Plot[pot[w,d][z],{z,-1,1},Exclusions->None],
DataPlot[s ((wef[[1;;p]])^2)+es[[1;;p]],{-1,1},Filling->Thread[Range[p]->es[[1;;p]]]],
PlotRange->{{-1,1},All},
AspectRatio->1.5,
ImageSize->200]
],
{{d,500,"depth"},0,1000},
{{w,0.25,"width"},0.05,0.95},
{{n,7},Range[4,12]},
{{p,10,"number of states"},Range[20]},
{{s,5,"scale factor"},1,20},ControlPlacement->Left,SaveDefinitions->True]

Teaching Examples

Legendre's equation: (1-(x^2)) (((∂^2)y(x))/(∂(x^2)))-2 x ((∂y(x))/(∂x))+n (n+1) y(x)==0

Solve Legendre’s equation using DSolve

DSolve[(1-(x^2)) (((∂^2)y(x))/(∂(x^2)))-2 x ((∂y(x))/(∂x))+n (n+1) y(x)==0,y,x]

Solution for initial conditions y(0)==1 and y'(0)==0

(Subscript[𝓎, n_])=DSolveValue[{(1-(x^2)) (((∂^2)y(x))/(∂(x^2)))-2 x ((∂y(x))/(∂x))+n (n+1) y(x)==0,y(0)==1,y'(0)==0},y,x]

Display the solution for arbitrary n

Manipulate[Plot[(Subscript[𝓎, n])(x),{x,-1,1},PlotRange->2],{n,0,10},SaveDefinitions->True]

Fixed Point iterative solution

FixedPoint[y|->y-∫∫((1-(x^2)) (((∂^2)y)/(∂(x^2)))-2 x ((∂y)/(∂x))+n (n+1) y)\[DifferentialD]x \[DifferentialD]x+((O[x])^5),1]//FullSimplify

Teaching Examples

FFT Computation of Contour Integrals

Relation to FFT

For a circular contour around the origin

z==r (e^(i θ))⟹dz==i r (e^(i θ))dθ

and so, for a unit contour (r=1)

(1/(2π i))∮(z^(n-1)) ((f'(z))/(f(z))) dz==(1/(2π))(∫_0^(2π))(e^(i n θ))((f'((e^(i θ))))/(f((e^(i θ)))))dθ

The (n^th) complex Fourier coefficient of g(θ) is defined by [mathworld.wolfram.com/FourierSeries.html]

(Subscript[c, n])=(1/(2π))(∫_0^(2π))(e^(i n θ))g(θ)dθ

The Fourier coefficients can be computed using the FFT by sampling g(θ) uniformly over [0,2π]

Application to (Zeta[s])

Riemann introduced the function ξ(s)

ξ(s_):=(s-1) (π^(-(s/2))) Γ((s/2)+1) (Zeta[s])

which makes the functional equation symmetric

((ξ(s))/(ξ(1-s)))//FullSimplify

and simplifies the Weierstrass product involving all the (non-trivial) roots (ZetaZero[k])

ξ(s)==(1/2)(∏_k)(1-(s/(ZetaZero[k])))

z|->1/z

Under z|->1/z, the critical line maps to a unit circle centered z=1 (Keiper 1992).

All roots (ZetaZero[k])==x+i t under z|->1/z—not assuming the RH, just noting that x∈(0,1)—lie within a circle of radius r~0.003≪1 centered at z=0

Reciprocal roots

The function ξ((1/z)) has roots ((ZetaZero[k])^(-1)). So, the spectral zeta sums

Z(n):=(∑_ρ)(1/(ρ^n))

are the moments of the following integrals:

Z(n):=(1/(2π i))∮(z^n)(∂_z)log(ξ((1/z)))dz≡-(n/(2π i))∮(z^(n-1))log(ξ((1/z)))dz

Computing the moments

Define the integrand

f(θ_)=(z^2)(∂_z)log(ξ((1/z)))/.z->(E^(I θ))//FullSimplify

The Fourier coefficients can be computed using the FFT via Fourier, sampling f(θ) uniformly over [0,2π], noting the required normalization factor (n^(-1/2)), where n is the number of samples

N[With[{n=(2^4),δ=(10^(-30`80))},-Fourier[(1/(Sqrt[n]))(f/@(2π ((Range[n]-1)/n)+δ))]//Re],20]//Column

Compare to the Maclaurin series expansion

(∂_s)log(ξ(s))+((O[s])^5)//FunctionExpand//FullSimplify

CoefficientList[N[%,20],s]//Column

Conclusions

Outcomes

Learning outcomes include:

a capability for model building and problem-solving

a good understanding of a range of computational methods

a solid understanding of Mathematica

Student Feedback

Analysis of student feedback from around 100 students/year shows a high level of satisfaction with these courses. In particular, the majority of students feel that:

they have gained a good understanding of concepts and principles in this field

they have become more competent in this area

they have learned how to apply principles to new situations

the content has been intellectually challenging

doing the assignments has been a valuable learning experience

Advantages/Disadvantages

These responses are very encouraging since these are the primary goals of my courses.

The principal disadvantage of this approach is that much greater effort is demanded of the both lecturer and student, compared to a traditional lecture course.

However, this extra effort is justified by the improvement in student's computational and problem-solving skills:

they are learning a tool widely used by scientists

Mathematica is interactive and it encourages student experimentation

Final Remarks

Mathematica is an unparalled teaching tool:

Powerful numerics, symbolics, visualization and graphics

Range of curated data sources in various formats, including load-on-demand data

Easy to create powerful user interfaces and stand-alone applications via Manipulate

“Research-based” exam questions

Large repository of code and examples at http://demonstrations.wolfram.com

The demonstrations source code is available does not need Mathematica to run.

Code

ComplexPlot

ComplexPlot[f_,{z_,a_,b_},opts___]:=Module[{g=z|->Evaluate[f],xmin,xmax,ymin,ymax},

{xmin,xmax}=Re[{a,b}];
{ymin,ymax}=Im[{a,b}];

Plot3D[\[LeftBracketingBar]g(x+I y)\[RightBracketingBar],{x,xmin,xmax},{y,ymin,ymax},
ColorFunction->({x,y}|->Hue[((arg(g(x+I y)))/(2 π))]),
ColorFunctionScaling->False,opts,PlotPoints->100,Mesh->5,MeshStyle->Gray,

MeshFunctions->{{x,y}|->(Abs[g(x+I y)]),{x,y}|->arg(g(x+I y))},

AxesLabel->{x,y,(Abs[f])}]
]

ComplexPlot[f_List,{z_,a_,b_},opts___]:=GraphicsRow@((g|->ComplexPlot[g,{z,a,b},opts])/@f)