Chemistry · Intermediate

Particle in a box

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

The particle in a box is the simplest quantum model of confinement: a particle trapped between impenetrable walls can only have certain standing-wave states with discrete energies. It shows how confinement produces quantization and gives a first model for conjugated pi electrons and nanoparticles.

Intuition

Think of a guitar string pinned at both ends. Only waves that fit an whole number of half-wavelengths between the pinned ends can persist. A quantum particle behaves like a wave, and if it is trapped between two walls where its wavefunction must be zero, only standing waves with an integer number of half-wavelengths are allowed. Shorter wavelength means higher momentum and higher energy, so the allowed energies rise as n squared. The lowest state still has nonzero energy, called zero-point energy, because squeezing a particle into a small region forces a spread in momentum. Making the box smaller raises all energies and spreads the levels further apart.

Key equations

−ℏ22md2ψdx2=Eψ,0<x<L
(1)

Time-independent Schrödinger equation inside the box, where the potential is zero.

ψn(x)=2Lsin⁡(nπxL)
(2)

Normalized wavefunctions, n = 1, 2, 3,...

En=n2h28mL2
(3)

Quantized energy levels, growing as n squared and falling as 1/L squared.

ΔE=En+1−En=(2n+1)h28mL2
(4)

Spacing between adjacent levels, which determines transition (absorption) wavelengths.

Derivation

  1. Set the potential to zero for 0 < x < L and infinite outside, so the wavefunction must vanish at x = 0 and x = L.
  2. Inside, solve the equation: ψ′′=−k2ψ with k2=2mEℏ2. The general solution is Asin⁡(kx)+Bcos⁡(kx).
  3. Boundary condition psi(0)=0 forces B = 0.
  4. Boundary condition ψ(L)=0 requires sin⁡(kL)=0, so k=nπL with n=1,2,3,... (n=0 gives no particle).
  5. Substitute k into E=ℏ2k22m to get En=n2π2ℏ22mL2=n2h28mL2.
  6. Normalize: the integral of |ψ|2 from 0 to L equals A2L/2=1, so A=2/L.

Worked example

Problem

An electron is confined to a one-dimensional box of length 1.0 nm. Find the n = 1 to n = 2 transition energy and the wavelength of light absorbed.

  1. Use h = 6.626e-34 J s, m = 9.109e-31 kg, L = 1.0e-9 m.
  2. Compute E_1 = h^2/(8mL^2) = (4.390e-67)/(8 × 9.109e-31 × 1.0e-18) = 6.02e-20 J (about 0.376 eV).
  3. E_2 = 4E_1 = 2.41e-19 J.
  4. Delta E = E_2 - E_1 = 3E_1 = 1.81e-19 J.
  5. Wavelength = hc/Delta E = (6.626e-34 × 3.00e8)/(1.81e-19) = 1.10e-6 m.

Answer Delta E ≈ 1.8e-19 J (about 1.13 eV); absorbed wavelength ≈ 1.1 micrometres (infrared).

Common mistakes

  • Allowing n = 0: this gives psi = 0 everywhere, meaning no particle.
  • Forgetting that the lowest energy is not zero; zero-point energy is E_1.
  • Thinking the probability is highest at the center for all states; for n = 2 there is a node at the center.
  • Using nanometres or electronvolts without converting to SI units in the formula.
  • Confusing the energy spacing (grows with n) with that of the harmonic oscillator (constant).

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

scene.py(164 lines)
import sys
import numpy as np
from manim import *
from blocks import *

# Particle in a 1D box (length L=1)
# Energy levels: E_n = n^2 * h^2 / (8 m L^2)
# Wavefunctions: psi_n(x) = sqrt(2/L) * sin(n * pi * x / L)

L = 1.0  # Box length
h_bar = 1.0545718e-34  # J s
m = 9.10938356e-31  # kg

def psi(n, x, L=L):
    """Wavefunction psi_n(x) for particle in a box."""
    if x < 0 or x > L:
        return 0.0
    return np.sqrt(2.0 / L) * np.sin(n * np.pi * x / L)

def energy(n, L=L):
    """Energy E_n in Joules."""
    return (n**2 * h_bar**2) / (8 * m * L**2)

# Precompute values for plotting
x_vals = np.linspace(0, L, 500)
n_values = [1, 2, 3]
psi_values = {n: [psi(n, x) for x in x_vals] for n in n_values}
energies = {n: energy(n) for n in n_values}

# Normalize energies for display (relative to ground state)
E1 = energy(1)
E_rel = {n: energies[n] / E1 for n in n_values}

class Main(Scene):
    def construct(self):
        TitleCard(self, "Particle in a Box", "Wavefunctions & Energy Levels")
        
        # Left: Wavefunctions
        # We plot psi(x) vs x. To make them visible, we might need to shift them vertically based on energy.
        # Let's plot them centered around their energy levels? No, psi is probability amplitude.
        # Standard representation: plot psi(x) and |psi(x)|^2.
        # Let's just plot psi(x) shifted by a factor of energy to separate them visually?
        # Or just plot them all from 0? Overlap is messy.
        # Let's plot psi_1, psi_2, psi_3 separately or stacked.
        # Stacked: psi_n(x) + offset_n.
        
        # Let's create a custom plot for wavefunctions
        # Axes
        axes_left = Axes(
            x_range=[0, 1, 0.2],
            y_range=[-1.5, 1.5, 0.5],
            x_length=5.0,
            y_length=4.0,
            axis_config={"color": C_DIM, "include_tip": True}
        )
        axes_left.to_edge(LEFT, buff=0.5)
        axes_left.move_to(ORIGIN + LEFT * 0.5)
        
        x_label = Text("x / L", font_size=24, color=WHITE).next_to(axes_left.x_axis, DOWN, buff=0.2)
        y_label = Text("psi(x)", font_size=24, color=WHITE).next_to(axes_left.y_axis, LEFT, buff=0.2)
        self.play(Create(axes_left), FadeIn(x_label), FadeIn(y_label), run_time=1.5)
        
        # Box boundaries
        box_left = Line(axes_left.n2p(0, 0), axes_left.n2p(0, 1.5), color=C_DIM, stroke_width=2)
        box_right = Line(axes_left.n2p(1, 0), axes_left.n2p(1, 1.5), color=C_DIM, stroke_width=2)
        self.play(Create(box_left), Create(box_right), run_time=0.5)
        
        # Plot wavefunctions
        # We will shift them vertically by their relative energy index * 2.0 to separate them
        # But psi is oscillatory. Let's just plot them at y=0, 2, 4?
        # Let's plot psi_1 at y=0, psi_2 at y=2, psi_3 at y=4?
        # Max psi is sqrt(2) ~ 1.41. So amplitude is ~1.5.
        # Shifts: 0, 3, 6?
        
        shifts = [0, 3, 6]
        colors = [C_MAIN, C_ACCENT, C_GOOD]
        
        curves = []
        for i, n in enumerate(n_values):
            # Create a function that returns psi(x) + shift
            def get_psi_shifted(x, n=n, s=shifts[i]):
                return psi(n, x) + s
            
            # Manim's plot expects a function of x.
            # We can plot the shifted version.
            curve = axes_left.plot(
                lambda x, n=n, s=shifts[i]: psi(n, x) + s,
                x_range=[0, 1],
                color=colors[i],
                use_smoothing=True
            )
            self.play(Create(curve), run_time=1)
            curves.append(curve)
            
            # Label n
            label = Text(f"n={n}", font_size=24, color=colors[i])
            label.next_to(axes_left.n2p(0.05, shifts[i] + 1.2), LEFT, buff=0.1)
            self.play(FadeIn(label), run_time=0.5)

        # Right: Energy Levels
        # Draw horizontal lines at y positions corresponding to energy
        # Let's use a separate set of axes or just lines on the right side
        
        axes_right = Axes(
            x_range=[0, 1, 0.5],
            y_range=[0, 10, 2],
            x_length=2.0,
            y_length=4.0,
            axis_config={"color": C_DIM, "include_tip": True}
        )
        axes_right.to_edge(RIGHT, buff=0.5)
        axes_right.move_to(ORIGIN + RIGHT * 0.5)
        
        y_label_right = Text("E_n / E_1", font_size=24, color=WHITE).next_to(axes_right.y_axis, LEFT, buff=0.2)
        self.play(Create(axes_right), FadeIn(y_label_right), run_time=1)
        
        # Draw energy levels
        # E1=1, E2=4, E3=9
        e_levels = [1, 4, 9]
        for i, e in enumerate(e_levels):
            # Line from x=0 to x=1 at height e
            line = Line(
                axes_right.n2p(0, e),
                axes_right.n2p(1, e),
                color=colors[i],
                stroke_width=3
            )
            self.play(Create(line), run_time=0.5)
            
            # Label
            label = Text(f"n={n_values[i]}, E={e}", font_size=20, color=colors[i])
            label.next_to(axes_right.n2p(0.1, e), LEFT, buff=0.1)
            self.play(FadeIn(label), run_time=0.5)
            
            # Arrow from wavefunction to energy level?
            # Connect the center of the wavefunction plot to the energy level?
            # Let's draw a dashed line from the box center to the energy level
            start_point = axes_left.n2p(0.5, shifts[i])
            end_point = axes_right.n2p(0.5, e)
            arrow = DashedLine(start_point, end_point, color=C_DIM, stroke_width=2)
            self.play(Create(arrow), run_time=0.5)

        StepCaption(self, "Energy is quantized: E_n proportional to n^2.")
        self.wait(1.5)


if __name__ == "__main__" and "--selftest" in sys.argv:
    # Test 1: psi(1, 0.5) should be max (sqrt(2))
    assert abs(psi(1, 0.5) - np.sqrt(2)) < 1e-9
    
    # Test 2: psi(2, 0.5) should be 0 (node)
    assert abs(psi(2, 0.5)) < 1e-9
    
    # Test 3: Energy ratio E2/E1 should be 4
    assert abs(energy(2) / energy(1) - 4) < 1e-9
    
    # Test 4: Energy ratio E3/E1 should be 9
    assert abs(energy(3) / energy(1) - 9) < 1e-9
    
    # Test 5: psi is zero outside box
    assert abs(psi(1, -0.1)) < 1e-9
    assert abs(psi(1, 1.1)) < 1e-9
    
    print("selftest ok")

The Manim scene code that draws this lesson's animation in the Signals AI app (Python, Manim Community).

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.