Tones and states: eigenproblems

A string has its tones, a drum its modes, and a particle in a potential its states. All of them are eigenproblems: equations that have a solution only for certain numbers, which are to be found together with the solution. This last part of the tutorial asks for the lowest of them.

Step 1: an eigenvalue is an unknown

import numpy as np
import sympy as sp
import pdemagic as pm

x, y = sp.symbols("x y", real=True)
E = sp.Symbol("E")

A string that is held at both ends swings in shapes \(v\) that obey \(-v'' = E\,v\). Write the equation as it stands, with a symbol for the eigenvalue, and say with eigenvalue= which symbol that is and how many of the lowest eigenvalues you want:

v = sp.Function("v")(x)

string = pm.Problem(
    sp.Eq(-v.diff(x, 2), E * v),
    domain=pm.Box({x: (0, 1)}),
    boundary=sp.Eq(v, 0),
    eigenvalue=(E, 4),
)
tones = pm.solve(string)
print(tones)
Solution(unknowns=['v'], grid=48, eigenvalues=4)

Each face has its condition, as in part 2. In an eigenproblem every condition gives zero.

Step 2: eigenvalues and eigenfunctions

tones.eigenvalues holds the eigenvalues, from the lowest. The frequency of a tone is the square root of its eigenvalue, and for a string the frequencies are whole multiples of the lowest one, \(\pi\):

print(np.round(np.sqrt(tones.eigenvalues) / np.pi, 6))
[1. 2. 3. 4.]

tones[v] holds the eigenfunctions, with the first axis counting them: tones[v][0] belongs to tones.eigenvalues[0].

print(tones[v].shape)
tones.plot()
The figure that the example above draws. The figure that the example above draws.
(4, 48)

In one dimension plot draws the lowest eigenfunctions together: half a wave, a whole wave, and so on. An eigenfunction is fixed only up to a factor. Here each has the integral of its square over the domain equal to one, and its largest value positive.

Step 3: a drum

In two dimensions the same equation, \(-\nabla^2 w = E\,w\), gives the modes of a membrane that is held along its edge. This drum is a rectangle, twice as long as it is wide:

w = sp.Function("w")(x, y)

drum = pm.Problem(
    sp.Eq(-pm.laplacian(w), E * w),
    domain=pm.Box({x: (0, 2), y: (0, 1)}),
    boundary=sp.Eq(w, 0),
    eigenvalue=(E, 4),
)
modes = pm.solve(drum)
print(np.round(modes.eigenvalues / np.pi**2, 6))
print(np.round(np.sqrt(modes.eigenvalues / modes.eigenvalues[0]), 3))
[1.25 2.   3.25 4.25]
[1.    1.265 1.612 1.844]

The first line is \(m^2/4 + n^2\) for the mode with \(m\) half waves along the long side and \(n\) along the short one. The second line shows why a drum does not sound like a string: its frequencies are no whole multiples of the lowest one.

In two dimensions plot draws one mode, the lowest unless state= names another. States are counted from zero:

modes.plot(state=2)
The figure that the example above draws. The figure that the example above draws.

Step 4: a round drum

Any domain with walls has its modes. On a disk the unknown is a function of the radius and the angle:

r, angle = sp.symbols("r alpha", real=True)
d = sp.Function("d")(r, angle)

round_drum = pm.Problem(
    sp.Eq(-pm.laplacian(d), E * d),
    domain=pm.Disk(r, angle, radius=1),
    boundary=sp.Eq(d, 0),
    eigenvalue=(E, 4),
)
round_modes = pm.solve(round_drum)
print(np.round(np.sqrt(round_modes.eigenvalues), 4))
round_modes.plot(state=1)
The figure that the example above draws. The figure that the example above draws.
[2.4048 3.8317 3.8317 5.1356]

These are the zeros of the Bessel functions, as the books have them. The second and the third mode share one eigenvalue: they are the same pattern, turned by a quarter of the circle. Modes of the same eigenvalue are returned as functions that are orthogonal to each other.

Step 5: the states of a potential

In quantum mechanics the eigenvalues are the energies that a particle can have. The harmonic oscillator is a particle in the potential \(x^2/2\): \(-\tfrac12\psi'' + \tfrac12 x^2\psi = E\,\psi\). It has no walls. It lives in free space, as the charges of part 1 did:

psi = sp.Function("psi")(x)

oscillator = pm.Problem(
    sp.Eq(-psi.diff(x, 2) / 2 + x**2 / 2 * psi, E * psi),
    domain=pm.FreeSpace(x),
    eigenvalue=(E, 5),
)
states = pm.solve(oscillator)
print(np.round(states.eigenvalues, 8))
[0.5 1.5 2.5 3.5 4.5]

These are the energies \(n + \tfrac12\) of the textbooks. In free space the states that are found are the bound ones: those that fade far away. The planner solves on a box that reaches as far as the highest state that you asked for, and a diagnostic says how far the states have faded at its faces:

box = states.plan.grid
print(np.round(box.lower, 1), np.round(box.upper, 1))
print(states.diagnostics["solution_boundary_ratio"] < 1e-9)
[-8.5] [8.5]
True

The lowest state is the bell \(e^{-x^2/2}/\pi^{1/4}\), which the result matches to eight digits:

(xs,) = states.axes
print(abs(states[psi][0] - np.exp(-(xs**2) / 2) / np.pi**0.25).max() < 1e-8)
states.plot(state=[0, 4])
The figure that the example above draws. The figure that the example above draws.
True

state= takes a list in one dimension, here the lowest state and the highest of the five.

What you have learned

  • An eigenproblem is an equation with a symbol for the eigenvalue, and eigenvalue=(E, n) asks for the lowest n eigenvalues.

  • solution.eigenvalues holds them, and solution[unknown][i] is the eigenfunction of the eigenvalue i.

  • Between walls an eigenproblem gives the modes of the domain, and in free space the bound states of a potential.

  • plot(state=...) chooses what is drawn.

Eigenproblems: bound states and Modes of cavities, drums and waveguides go on from here, and the gallery has a drum and the states of the oscillator. That was the tutorial. What to read next says where to go now.