Numerical Techniques

One of the advantages of Python is the selection of libraries which greatly simplify complex tasks. For example NumPy allows for matrix multiplication and other vector operations as well as more complex operations such as eigenvalue evaluation which for other languages may require additional set up (such as workspaces in fortran).

For numerical techniques for solving ODEs, SciPy provides the general odeint function which can integrate a system of differential equations in a single line. In the background it calls from the fortran odepack, thus making it quick but only requires minimal boilerplate to call (unlike GSL as used in the current C++ course).

Many numerical algorithms, namely finite difference methods, require looping over grid points. In Python this would be excessively slow (video showing looping comparison with explanation), however using the NumPy library C/C++ and fortran operations can speed up such tasks by pushing repeated operations into compiled code (also shown in video). Now loops can be replaced by slicing and indexing, all done within a single line. Although not strictly faster than a low-level language equivalent, the time saved in writing the Python version using NumPy to replace the loops can make for an efficient program.

From the students perspective, the simplicity of these Pythonified algorithms allows for more to be investigated. For example, rather than spending time trying to figure out how to handle the output of a Fast Fourier Transform, NumPy and SciPy provide the fftshift function to place the zero frequency at the origin. This would give students more time to investigate complex diffraction patterns and think about the Physics while using the code as a tool.

Hopefully the reduced debugging and writing time would allow for different physical situations and therefore different numerical algorithms to be used. This would show that there is more to life than RK4.

Below we shall point to some Demo notebooks using particular numerical algorithms as well as resources providing explanation of the technique

Algorithms and Resources

From SciPy and NumPy:

scipy.odeint Gyroscope odeint
scipy.quad Perturbation Theory quad
numpy.eig Linear Chain eig

Established Numerical Techniques written in Python:

Lax & Lax-Wendroff Wave Equation Numerical Recipes: The Art of Scientific Computing Book, Solving PDEs numerically & Algorithm summaries in 1D and 2D
Split Step Fourier method Reflectionless Potential Quantum Python & Split-step wiki
Shooting method Finite Square Well Numerov Method
Monte-Carlo Bateman Equation Monte Carlo wiki (see also Ising model notebooks for Metropolis algorithm)
Lattice Boltzmann Flow onto a barrier LBM

and others

Custom Algorithms:

Cherenkov Radiation Notebook  
Light Ray Caustic Caustic Ray Transfer Matrix Analysis & PyCav Optics Docs
Aidan Crilly

Aidan Crilly

Physics of Other Stuff

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo