Blog

A blog of Python-related topics and code.

Interactive particle-in-a-box wavefunctions in Jupyter

A very quick plot of particle-in-a-box wavefunctions with interactive control over the box length, $L$ – this kind of thing is very easy with Jupyter and ipywidgets' interact method: Just define a function to plot the wavefunction for a provided argument $L$ and pass it to interact along with a range and stepsize of values of $L$ and a slider will appear above the plot. Event callbacks and range-checking are all handled for you.

The arcsine law

Suppose a fair coin is tossed $N$ times and the number of "heads", $n_\mathrm{heads}$, and "tails", $n_\mathrm{tails}$, recorded after each toss. Over the course of the trial, how many times is the number of heads recorded greater than the number of tails? Naive intuition might lead to the expectation that as $N$ increases the number of times "heads" is in the lead increases in proportion.

Atomic term symbols

The problem of predicting the term symbols for states derived from a $nl^r$ atomic configuration (without using group theory!) provides a good use of Python's collections and itertools libraries.

A customizable Ebbinghaus illusion

The Ebbinghaus illusion is a famous visual effect based on the perception of the relative size. Two circles of the same size are surrounded in one case by obviously larger circles and in the other by obviously smaller circles. The former is perceived as being smaller than the latter, as illustrated below.

The Reutersvärd Triangle

The Reutersvärd Triangle is an example of an impossible object: a two-dimensional optical illusion perceived as a projection of a three-dimensional object that cannot exist. The Python code below creates an SVG image of Reutersvärd's impossible triangular arrangement of cubes, similar to the more famous Penrose Triangle.