Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Operators and Differential Equations

Quantum mechanics is written in the language of operators and differential equations. But underneath that calculus lies a simpler and more powerful truth: quantum mechanics is linear algebra. Wavefunctions are vectors, operators are matrices, and the Schrodinger equation is the eigenvalue problem Av=λvA\mathbf{v} = \lambda\mathbf{v} in disguise. Undergraduate courses often bury this under derivatives and integrals; this page brings it to the surface first, then returns to the differential equations as the tools for working in one particular basis.

Functions are vectors, operators are matrices

A function is a vector with one component per point

Take any function and evaluate it at NN points x=(x1,x2,,xN)x = (x_1, x_2, \ldots, x_N). The list of values is a vector with NN components. For example f(x)=x2f(x) = x^2 sampled at x=(0,1,2,3,4)x = (0,1,2,3,4) becomes the vector (0,1,4,9,16)(0,1,4,9,16).

Now let the grid get finer, NN\to\infty with spacing h0h\to 0. The vector gains a component for every point xx, and in that limit the function is an infinite-dimensional vector. The value ψ(x)\psi(x) plays the role of “the component at xx,” exactly as viv_i is the component of v\mathbf{v} along basis direction ii.

The inner product becomes an integral

This is the link that makes the analogy precise. The dot product of two vectors sums the products of matching components. For function-vectors, that sum over grid points, weighted by the spacing hh, is a Riemann sum, and in the fine-grid limit it becomes an integral:

fg=if(xi)g(xi)h  h0  f(x)g(x)dx.\langle f \mid g \rangle = \sum_i f^*(x_i)\,g(x_i)\,h \;\xrightarrow[h\to 0]{}\; \int f^*(x)\,g(x)\,dx.

So the quantum-mechanical inner product ψϕ=ψϕdx\langle\psi\mid\phi\rangle = \int\psi^*\phi\,dx is nothing more than the dot product from the previous page, carried to infinite dimensions. Everything built on the dot product carries over verbatim: normalization ψ2dx=1\int|\psi|^2\,dx = 1 is just ψ=1|\psi| = 1, and orthogonal wavefunctions (ψmψndx=0\int\psi_m^*\psi_n\,dx = 0) are just perpendicular vectors.

An operator is a matrix

A linear operator takes a function and returns a function, that is, it takes a vector and returns a vector. Any linear map on vectors is a matrix, so every quantum operator is a matrix acting on the function-vector. The derivative operator, for instance, becomes the finite-difference matrix built in the next section. This gives the full dictionary between the linear algebra you already know and the quantum mechanics ahead:

Linear algebra (finite dimensions)Quantum mechanics (functions)
vector v\mathbf{v}wavefunction ψ(x)\psi(x)
component viv_ivalue ψ(x)\psi(x)
dot product ab=iaibi\langle \mathbf{a}\mid\mathbf{b}\rangle = \sum_i a_i^* b_iinner product ψϕ=ψϕdx\langle\psi\mid\phi\rangle = \int\psi^*\phi\,dx
normalized v=1\lvert\mathbf{v}\rvert = 1normalized ψ2dx=1\int\lvert\psi\rvert^2 dx = 1
orthonormal basis ei\mathbf{e}_iorthonormal functions ϕn(x)\phi_n(x)
matrix AAoperator A^\hat A (such as x^\hat x, p^\hat p, H^\hat H)
eigenvector equation Av=λvA\mathbf{v} = \lambda\mathbf{v}eigenfunction equation A^ψ=aψ\hat A\psi = a\psi
eigenvalue λ\lambdameasured value aa (energy, momentum)
symmetric / Hermitian matrixHermitian operator (real eigenvalues)
expansion v=iciei\mathbf{v} = \sum_i c_i\mathbf{e}_isuperposition ψ=ncnϕn\psi = \sum_n c_n\phi_n

The rest of this page makes the “operator is a matrix” half concrete: we build the derivative as an explicit matrix, see why operator order matters, and then meet the differential equations that these operators live in.

The derivative as a finite-difference matrix

We approximate the first derivative by a centered difference, the slope between the neighbor on the left and the neighbor on the right:

dψdxxiψ(xi+1)ψ(xi1)2h.\frac{d\psi}{dx}\bigg|_{x_i} \approx \frac{\psi(x_{i+1}) - \psi(x_{i-1})}{2h}.

Written as a matrix acting on the sampled vector (with one-sided formulas at the two boundaries), this is

D1=12h(3410010100010100010100143).D_1 = \frac{1}{2h} \begin{pmatrix} -3 & 4 & -1 & 0 & 0 \\ -1 & 0 & 1 & 0 & 0 \\ 0 & -1 & 0 & 1 & 0 \\ 0 & 0 & -1 & 0 & 1 \\ 0 & 0 & 1 & -4 & 3 \end{pmatrix}.
import numpy as np

n = 5
x = np.linspace(0, 4, n)
h = x[1] - x[0]
psi = x**2

D1 = (1 / (2 * h)) * np.array([
    [-3, 4, -1, 0, 0],
    [-1, 0, 1, 0, 0],
    [0, -1, 0, 1, 0],
    [0, 0, -1, 0, 1],
    [0, 0, 1, -4, 3],
])

print("finite-difference derivative of x^2:", D1 @ psi)
print("exact derivative 2x               :", 2 * x)
finite-difference derivative of x^2: [0. 2. 4. 6. 8.]
exact derivative 2x               : [0. 2. 4. 6. 8.]

The second derivative uses the three-point stencil ψi+12ψi+ψi1\psi_{i+1} - 2\psi_i + \psi_{i-1} over h2h^2. This matrix is the discrete kinetic-energy operator, the heart of every numerical Schrodinger solver. Below we build it on a fine grid, apply it to sinx\sin x, and recover sinx-\sin x, since d2dx2sinx=sinx\frac{d^2}{dx^2}\sin x = -\sin x.

Source
import numpy as np
import matplotlib.pyplot as plt

N = 200
x = np.linspace(0, 2 * np.pi, N)
h = x[1] - x[0]

# Second-derivative matrix, tridiagonal (1, -2, 1) / h^2
D2 = (np.diag(np.ones(N - 1), 1)
      - 2 * np.diag(np.ones(N))
      + np.diag(np.ones(N - 1), -1)) / h**2

psi = np.sin(x)
d2psi = D2 @ psi

fig, ax = plt.subplots(figsize=(7, 3.6))
ax.plot(x, psi, 'k', lw=2, label=r'$\psi = \sin x$')
ax.plot(x[1:-1], d2psi[1:-1], color='#d1495b', lw=2, label=r'$D_2\,\psi$ (numerical)')
ax.plot(x, -np.sin(x), '--', color='#66a182', lw=2, label=r'$-\sin x$ (exact)')
ax.axhline(0, color='gray', lw=0.6)
ax.set_xlabel('x')
ax.legend(fontsize=9, loc='upper right')
ax.set_title('Fig.1 The second-derivative matrix turns sin x into -sin x')
plt.tight_layout()
plt.show()
<Figure size 700x360 with 1 Axes>

Operator order matters

Matrices, and therefore operators, generally do not commute: ABBAAB \neq BA. With

A=(1201),B=(0110),A = \begin{pmatrix} 1 & 2 \\ 0 & 1 \end{pmatrix}, \qquad B = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix},

we get AB=(2110)AB = \begin{pmatrix} 2 & 1 \\ 1 & 0 \end{pmatrix} but BA=(0112)BA = \begin{pmatrix} 0 & 1 \\ 1 & 2 \end{pmatrix}.

import numpy as np

A = np.array([[1, 2], [0, 1]])
B = np.array([[0, 1], [1, 0]])

print("AB =\n", A @ B)
print("BA =\n", B @ A)
print("\ncommutator AB - BA =\n", A @ B - B @ A)
AB =
 [[2 1]
 [1 0]]
BA =
 [[0 1]
 [1 2]]

commutator AB - BA =
 [[ 2  0]
 [ 0 -2]]

The order matters because applying a shear then a rotation is not the same as rotation then shear. In quantum mechanics this same non-commutation, packaged as the commutator [A^,B^]=A^B^B^A^[\hat A, \hat B] = \hat A\hat B - \hat B\hat A, is exactly what forbids simultaneous sharp values of position and momentum. It is the algebra behind the uncertainty principle.

Ordinary differential equations

A differential equation relates a function to its derivatives. An ordinary differential equation (ODE) involves derivatives with respect to a single variable. Two show up everywhere in chemistry.

First order: exponential growth and decay

The rate of change is proportional to the amount present. With k<0k < 0 this is radioactive decay or a first-order reaction; with k>0k > 0 it is unchecked growth. The solution is the exponential because ekte^{kt} is the one function equal to its own derivative up to the constant kk.

Second order: oscillation

Here the second derivative is proportional to the negative of the function, so the solution oscillates. This is a swinging pendulum, a vibrating bond, and, with xx in place of tt, the spatial shape of a particle-in-a-box wavefunction. Using Euler’s formula the same solution reads y=Ceiωt+Deiωty = C e^{i\omega t} + D e^{-i\omega t}, which is why complex exponentials and oscillations are inseparable.

Source
import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10, 400)

fig, axes = plt.subplots(1, 2, figsize=(10, 3.6))

# First order: decay for several rates
for k, c in zip([-0.2, -0.5, -1.0], ['#66a182', '#edae49', '#d1495b']):
    axes[0].plot(t, np.exp(k * t), color=c, lw=2, label=f'k = {k}')
axes[0].set_title(r"Fig.2a First order: $y' = ky$ (decay)")
axes[0].set_xlabel('t')
axes[0].set_ylabel('y')
axes[0].legend(fontsize=9)

# Second order: oscillation for several frequencies
for w, c in zip([1.0, 1.5, 2.0], ['#66a182', '#edae49', '#d1495b']):
    axes[1].plot(t, np.cos(w * t), color=c, lw=2, label=fr'$\omega$ = {w}')
axes[1].set_title(r"Fig.2b Second order: $y'' = -\omega^2 y$ (oscillation)")
axes[1].set_xlabel('t')
axes[1].axhline(0, color='gray', lw=0.6)
axes[1].legend(fontsize=9)

plt.tight_layout()
plt.show()
<Figure size 1000x360 with 2 Axes>

Partial differential equations

A partial differential equation (PDE) involves derivatives with respect to more than one variable, for example both position xx and time tt. The two central equations of the course are PDEs:

Wave equation:2ut2=c22ux2,Schrodinger:iΨt=H^Ψ.\text{Wave equation:}\quad \frac{\partial^2 u}{\partial t^2} = c^2\frac{\partial^2 u}{\partial x^2}, \qquad \text{Schrodinger:}\quad i\hbar\frac{\partial \Psi}{\partial t} = \hat H \Psi.

Separation of variables

The workhorse technique is separation of variables: guess that the solution factors into pieces that each depend on only one variable,

Ψ(x,t)=ψ(x)T(t).\Psi(x, t) = \psi(x)\,T(t).

Substituting this guess turns one PDE into two independent ODEs, one in xx and one in tt, tied together by a shared constant. For the Schrodinger equation the spatial ODE is the time-independent Schrodinger equation H^ψ=Eψ\hat H \psi = E\psi, and the temporal ODE gives the phase factor T(t)=eiEt/T(t) = e^{-iEt/\hbar}.

This is why the earlier ODE solutions matter: the spatial equation is a second-order ODE whose oscillating solutions are the stationary states, and the temporal equation is a first-order ODE whose solution is a complex-exponential phase. Notice the recurring pattern of the whole appendix: the eigenvalue problem H^ψ=Eψ\hat H\psi = E\psi is the operator-as-matrix idea, the energies EE are eigenvalues, and the wavefunctions ψ\psi are eigenvectors.

Problems

Problem 1: Read off a derivative matrix

Using the first-derivative matrix D1D_1 above with h=1h=1, apply it to the constant vector ψ=(5,5,5,5,5)\psi = (5,5,5,5,5). What do you expect, and why?

Problem 2: Solve a decay ODE

A first-order reaction obeys dy/dt=0.3ydy/dt = -0.3\,y with y0=2y_0 = 2. Write y(t)y(t) and find the half-life.

Problem 3: Verify an oscillator solution

Show that y(t)=Acos(ωt)+Bsin(ωt)y(t) = A\cos(\omega t) + B\sin(\omega t) satisfies y=ω2yy'' = -\omega^2 y.

Problem 4: A commutator

Compute the commutator [A,B]=ABBA[A, B] = AB - BA for A=(1001)A = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} and B=(0110)B = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}.

Problem 5: Separation of variables setup

Insert Ψ(x,t)=ψ(x)T(t)\Psi(x,t) = \psi(x)T(t) into itΨ=22mx2Ψi\hbar\,\partial_t\Psi = -\frac{\hbar^2}{2m}\partial_x^2\Psi and divide by ψT\psi T. Show that one side depends only on tt and the other only on xx, so both equal a constant.

Problem 6: Build a second-derivative matrix

Modify the code to build D2D_2 on a grid of N=100N = 100 points over [0,π][0, \pi], apply it to cosx\cos x, and check that you recover cosx-\cos x.

Problem 7: Which ODE?

A bond vibrates about equilibrium with restoring force proportional to displacement. Write the differential equation for the displacement y(t)y(t) and state its general solution.

Problem 8: Non-commuting rotations

Numerically verify that a 2D shear and a 2D rotation do not commute by computing ABBAAB - BA for the shear and rotation matrices from the previous page on vectors and linear algebra.