A blog of Python-related topics and code.
The population dynamics simulation known as Wa-Tor was described in a previous post. When carried out on a grid with periodic boundary conditions, the Wa-Tor "universe" is topologically equivalent to a torus, as depicted below using the code provided here.
An example in Chapter 7 of the scipython book describes the numerical solution of the two-dimensional heat equation for a flat plate with edges held at a fixed temperature.
The code below, torus.py
, defines a class Torus
for drawing an SVG image of a torus. The Torus
class itself is a subclass of Shape
, a more general class for depicting 3D objects in an SVG image, defined in shape.py
. A usage example is given in the code of draw_torus.py
, which creates this image:
The scipy.optimize.curve_fit
routine can be used to fit two-dimensional data, but the fitted data (the ydata
argument) must be repacked as a one-dimensional array first. The independent variable (the xdata
argument) must then be an array of shape (2,M)
where M
is the total number of data points.
As described in the previous blog post charged particle moving in crossed constant magnetic and electric fields exhibits a drift velocity, $(\boldsymbol{E}\times\boldsymbol{B})/B^2$, perpendicular to both $\boldsymbol{E}$ and $\boldsymbol{B}$. The particle's trajectory in this situation can be found analytically. For an arbitrary $\boldsymbol{E}$, some kind of numerical integration of the equation of motion is usually necessary, but the force that the particle experiences at an instant is perpendicular to to the electric field and the particle therefore undergoes its gyromotion along an isocontour of electrostatic potential, $V$ (since $\boldsymbol{E} = -\nabla V$).