Classical vs Quantum particle in a box¶
The particle in a box is a toy model of an electron (or atom, molecule, or small quantum object) trapped in some region of space .
The positional information of a quantum “particle” is described by a quantum wave function , which is obtained by solving the Schrödinger equation with boundary conditions.
Wave functions are standing waves, just as in the vibrating guitar string problem, with one major difference: a quantum wave function has a probabilistic meaning and hence is completely different from the classical notion of a “wave”.
According to classical mechanics, in the absence of any attractive interactions the particle bounces back and forth between the walls with constant speed. We therefore expect to find it with equal probability at all locations .
According to quantum mechanics, the quantum particle in the box is found in some regions with high probability and in others with little or zero probability.

Figure 1:Classical (A) versus quantum (B-F) behavior of a particle in a box. The horizontal axis is position; the vertical axis shows the real (blue) and imaginary (red) parts of the wavefunction . States B, C, D are the eigenfunctions of the Hamiltonian, while E and F are not.
Solving the Schrödinger Equation for the Particle in a Box (PIB)¶
Figure 2:Particle in a box subject to infinitely high potential walls.
The Schrödinger equation for a particle in a box (PIB) is defined by a Hamiltonian operator that incorporates a potential energy which is infinitely large at the boundaries of the box and zero inside. This potential confines the particle within the box, where it can only possess kinetic energy.
The potential energy for PIB is defined:
The boundary conditions are:
The Hamiltonian operator in this case accounts only for kinetic energy:
Now, we have all the necessary ingredients to solve the time-independent Schrödinger equation for the 1D PIB:
Substituting the Hamiltonian, we get:
where is a positive real number that relates the particle’s energy to its wavefunction.
Solution and Boundary Conditions¶
Mathematically, the form of the 1D PIB problem is similar to the ordinary differential equation (ODE) used in the 1D vibrating guitar string problem. The key differences lie in the constant coefficients and the interpretation of the wavefunction.
The general solution to this differential equation is:
Applying the boundary condition , we find that , leaving us with:
Applying the boundary condition , we get:
This condition is satisfied when:
Thus, the wavefunction becomes:
Using the relationship , we can express the energy levels as:
The quantization of energy results from confining the wavefunction within a finite space. This is the reason bound states exhibit quantized energy levels. Atoms, molecules, and solids all possess discrete energy levels due to similar constraints.
Wavefunctions Must Be Normalized¶
Next, we determine the constant coefficient by enforcing the normalization condition:
$$ \int_0^L \psi_n(x)^2 , dx = 1
$$
To evaluate the integral, we use the trigonometric identity
Since the integral of over a full period from 0 to is zero, we are left with:
Solving for , we determine the normalization constant, which ensures that the square of the wavefunction integrates to 1.
PIB Eigenfunctions and Eigenvalues¶
Source
import numpy as np
import matplotlib.pyplot as plt
# Parameters
L = 1.0 # Length of the box
x = np.linspace(0, L, 1000) # Position array
n_max = 5 # Maximum quantum number to display
# Constants
hbar = 1.0545718e-34 # Reduced Planck's constant (J·s)
m = 9.10938356e-31 # Mass of an electron (kg)
# Functions
def psi_n(n, x, L):
"""Wavefunction for a particle in a 1D box."""
return np.sqrt(2 / L) * np.sin(n * np.pi * x / L)
def psi_n_squared(n, x, L):
"""Probability density (wavefunction squared)."""
return psi_n(n, x, L) ** 2
def energy_levels(n, L):
"""Energy level for the particle in the box."""
return (n**2 * np.pi**2 * hbar**2) / (2 * m * L**2)
# Energy formula string
energy_formula = r"$E_n = \frac{n^2 \pi^2 \hbar^2}{2mL^2}$"
# Plotting
fig, axs = plt.subplots(1, 2, figsize=(8, 6), sharey=True)
# Plot wavefunctions in the first subplot
for n in range(1, n_max + 1):
wavefunction = psi_n(n, x, L)
axs[0].plot(x, wavefunction + n**2, label=f'n={n}')
axs[0].hlines(n**2, 0, L, colors='gray', linestyles='dashed') # Energy level lines
# Wavefunction plot labels and title
axs[0].set_xlabel('Position (x)', fontsize=12)
axs[0].set_ylabel(r'$\psi_n(x)$', fontsize=12)
axs[0].legend(loc='upper right', bbox_to_anchor=(1.15, 1))
# Plot wavefunction squared (probability densities) in the second subplot
for n in range(1, n_max + 1):
wavefunction_squared = psi_n_squared(n, x, L)
axs[1].plot(x, wavefunction_squared + n**2, label=f'n={n}')
axs[1].hlines(n**2, 0, L, colors='gray', linestyles='dashed') # Energy level lines
# Probability density plot labels
axs[1].set_xlabel('Position (x)', fontsize=12)
axs[1].set_ylabel(r'$|\psi_n(x)|^2$', fontsize=12)
# Display the energy formula and levels in the second subplot
for n in range(1, n_max + 1):
energy_value = energy_levels(n, L)
axs[1].text(L, n**2, f"$E_{n}$ = {energy_value:.2e} J", verticalalignment='bottom', fontsize=12)
# Overall title for the figure
fig.suptitle(f'Wavefunctions and Energies for a 1D Particle in a Box (n=1 to n={n_max})')
# Make room for labels outside plot and improve layout
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.show()
Discrete energy levels and zero point energy¶
Quantum particles are never at rest
The lowest energy an electron in a box can have is at , and it is not zero!
Keeping in mind that the energy is purely kinetic, this means a quantum particle never ceases its motion.
The spacing of energy levels is finite and depends on the size of the box:
Increasing Box size leads to more classical behavior
As the box size is increased, the energy spacing gets smaller.
Thus quantum effects are more pronounced when an electron is bound in smaller regions of space.
Source
import numpy as np
import matplotlib.pyplot as plt
# Constants (set h^2/8m = 1 for simplicity)
L1 = 1.0
L2 = 2.0
n_max = 5
def energy_levels(L, n_max):
n = np.arange(1, n_max+1)
E = (n**2) / (L**2) # scaled energy
return n, E
# Compute for two box sizes
n, E1 = energy_levels(L1, n_max)
_, E2 = energy_levels(L2, n_max)
fig, axs = plt.subplots(1, 2, figsize=(12, 5), sharey=True)
# Left: small box (L=1)
for i, E in enumerate(E1, start=1):
axs[0].hlines(E, 0.9, 1.1, colors="tab:blue", linewidth=3)
axs[0].text(1.15, E, f"n={i}", va="center")
axs[0].set_title("Small box (L=1)\nLarger spacing")
axs[0].set_xlim(0.8, 1.5)
axs[0].set_ylabel("Energy (scaled units)")
# Right: larger box (L=2)
for i, E in enumerate(E2, start=1):
axs[1].hlines(E, 0.9, 1.1, colors="tab:green", linewidth=3)
axs[1].text(1.15, E, f"n={i}", va="center")
axs[1].set_title("Larger box (L=2)\nSmaller spacing")
axs[1].set_xlim(0.8, 1.5)
# Add zero-point energy annotation
axs[0].annotate("Zero-point energy\n(n=1)", xy=(1.0, E1[0]), xytext=(1.3, E1[0]+2),
arrowprops=dict(arrowstyle="->"))
for ax in axs:
ax.set_xticks([])
ax.set_xlabel("Particle in a box")
ax.grid(True, axis="y", alpha=0.3)
plt.suptitle("Discrete Energy Levels and Zero-Point Energy", fontsize=14)
plt.tight_layout()
plt.show()
Non-uniform probabilities and nodes¶
Nodes imply zero probability to find an electron in the box.
at nodal points, which means zero probability.
This sharply contradicts classical mechanics, which bases its prediction on purely particle-like motion of the electron.
The existence of nodes implies a wave-like character of the electron.
There are nodes for quantum state
Recall that the sine function hits zero at integer multiples of : when
The wavefunction then has nodes at the points , , , ..., .
Note that we do not count the and points as nodes, because they are part of the boundary conditions that apply to all wavefunctions.
For instance, the nodes are at and .
For instance, the nodes are at , , and .
Source
import numpy as np
import matplotlib.pyplot as plt
# Parameters
n = 4
L = 1.0
Nsamples = 6000
bins = 60
# Grid and eigenstate
x = np.linspace(0, L, 1000)
psi = np.sqrt(2/L) * np.sin(n*np.pi*x/L) # normalized
prob = psi**2
# Node locations (exclude 0 and L)
nodes = np.arange(1, n) * L / n
# Monte Carlo sampling via rejection
rng = np.random.default_rng(0)
samples = []
while len(samples) < Nsamples:
u = rng.random(20000)
x_prop = L * rng.random(20000)
accept = u < (np.sin(n*np.pi*x_prop/L)**2)
samples.extend(x_prop[accept].tolist())
samples = np.array(samples[:Nsamples])
# Plot
fig, axs = plt.subplots(1, 3, figsize=(14, 4))
# 1) psi_n(x)
axs[0].plot(x, psi, linewidth=2)
for xn in nodes:
axs[0].axvline(xn, linestyle="--", linewidth=1)
axs[0].set_title(rf"$\psi_{n}(x)$ with {n-1} nodes")
axs[0].set_xlabel("x")
axs[0].set_ylabel(r"$\psi_n(x)$")
axs[0].set_xlim(0, L)
axs[0].grid(True, alpha=0.3)
# 2) |psi|^2
axs[1].plot(x, prob, linewidth=2)
for xn in nodes:
axs[1].axvline(xn, linestyle="--", linewidth=1)
axs[1].set_title(rf"$|\psi_{n}(x)|^2$ (zero at nodes)")
axs[1].set_xlabel("x")
axs[1].set_ylabel(r"$|\psi_n(x)|^2$")
axs[1].set_xlim(0, L)
axs[1].grid(True, alpha=0.3)
# 3) Histogram vs analytic |psi|^2
axs[2].hist(samples, bins=bins, range=(0, L), density=True, alpha=0.35, label="Samples from $|\psi|^2$")
axs[2].plot(x, prob, linewidth=2, label="Analytic $|\psi|^2$")
for xn in nodes:
axs[2].axvline(xn, linestyle="--", linewidth=1)
axs[2].set_title("Non-uniform probability & nodes")
axs[2].set_xlabel("x")
axs[2].set_ylabel("Probability density")
axs[2].set_xlim(0, L)
axs[2].legend()
axs[2].grid(True, alpha=0.3)
plt.suptitle("Non-uniform probabilities and nodes in a 1D box (n=4)", fontsize=14)
plt.tight_layout()
plt.show()<>:52: SyntaxWarning: invalid escape sequence '\p'
<>:53: SyntaxWarning: invalid escape sequence '\p'
<>:52: SyntaxWarning: invalid escape sequence '\p'
<>:53: SyntaxWarning: invalid escape sequence '\p'
/tmp/ipykernel_3150/3569254680.py:52: SyntaxWarning: invalid escape sequence '\p'
axs[2].hist(samples, bins=bins, range=(0, L), density=True, alpha=0.35, label="Samples from $|\psi|^2$")
/tmp/ipykernel_3150/3569254680.py:53: SyntaxWarning: invalid escape sequence '\p'
axs[2].plot(x, prob, linewidth=2, label="Analytic $|\psi|^2$")

On time-dependence¶
Pure states¶
Pure states correspond to time-independent probability distribution.
Below we visualize the wavefunction and its square for .
Source
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
# Parameters
L = 1.0 # Length of the box
hbar = 1.0 # Set hbar = 1 for simplicity
m = 1.0 # Set mass = 1 for simplicity
# Define spatial and time arrays
x = np.linspace(0, L, 200)
t = np.linspace(0, 10, 200)
n = 2
# Define energy for nth state
def energy_n(n, L):
return (n**2 * np.pi**2 * hbar**2) / (2 * m * L**2)
# Define wavefunction for nth state
def psi_total(n, x, L, t):
E_n = energy_n(n, L)
return np.sqrt(2 / L) * np.sin(n * np.pi * x / L) * np.exp(-1j * E_n * t / hbar)
# Set up the figure and axis
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 8))
# Set limits for the wavefunction and wavefunction squared
ax1.set_xlim(0, L)
ax1.set_ylim(-2, 2)
ax2.set_xlim(0, L)
ax2.set_ylim(0, 4)
# Set labels for the wavefunction plot
ax1.set_xlabel('Position (x)', fontsize=14)
ax1.set_ylabel(r'Re[$\psi(x,t)$]', fontsize=14)
ax1.set_title('Time Evolution of Wavefunction', fontsize=16)
# Set labels for the squared wavefunction plot
ax2.set_xlabel('Position (x)', fontsize=14)
ax2.set_ylabel(r'$|\psi(x,t)|^2$', fontsize=14)
ax2.set_title('Probability Density', fontsize=16)
### Animation settings
# Initialize the wavefunction and its square plots
line_real, = ax1.plot([], [], lw=2)
line_prob, = ax2.plot([], [], lw=2)
# Initialization function for the plot
def init():
line_real.set_data([], [])
line_prob.set_data([], [])
return line_real, line_prob
# Animation function which updates the plot each frame
def animate(i):
t_val = t[i]
psi = psi_total(n, x, L, t_val)
psi_real = np.real(psi)
psi_squared = np.abs(psi)**2
line_real.set_data(x, psi_real)
line_prob.set_data(x, psi_squared)
return line_real, line_prob
# Create the animation
ani = FuncAnimation(fig, animate, init_func=init, frames=len(t), interval=150, blit=True)
plt.close(fig) # Prevents static display of the last frame
HTML(ani.to_jshtml())Mixed states¶
Mixed states show time dependence. Below we visualize a linear combination of the first two eigenfunctions of the PIB.
Step-by-Step illustration of time-dependence
Source
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
# Parameters
L = 1.0 # Length of the box
hbar = 1.0 # Set hbar = 1 for simplicity
m = 1.0 # Set mass = 1 for simplicity
n_states = [1, 2] # Quantum numbers for the superposition
coeffs = [1, 1] # Coefficients for the superposition
coeffs = np.array(coeffs) / np.sqrt(np.sum(np.array(coeffs) ** 2)) # Normalize coefficients
# Define spatial and time arrays
x = np.linspace(0, L, 200)
t = np.linspace(0, 10, 200)
# Define wavefunction for nth state
def psi_n(n, x, L):
return np.sqrt(2 / L) * np.sin(n * np.pi * x / L)
# Define energy for nth state
def energy_n(n, L):
return (n**2 * np.pi**2 * hbar**2) / (2 * m * L**2)
# Define time-dependent wavefunction
def psi_total(x, t, L, coeffs, n_states):
psi_t = np.zeros_like(x, dtype=complex)
for idx, n in enumerate(n_states):
psi_x = psi_n(n, x, L)
E_n = energy_n(n, L)
time_factor = np.exp(-1j * E_n * t / hbar)
psi_t += coeffs[idx] * psi_x * time_factor
return psi_t
# Set up the figure and axis
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11, 8))
# Set limits for the wavefunction and wavefunction squared
ax1.set_xlim(0, L)
ax1.set_ylim(-2, 2)
ax2.set_xlim(0, L)
ax2.set_ylim(0, 4)
# Set labels for the wavefunction plot
ax1.set_xlabel('Position (x)', fontsize=14)
ax1.set_ylabel(r'Re[$\psi(x,t)$]', fontsize=14)
ax1.set_title('Time Evolution of Wavefunction', fontsize=16)
# Set labels for the squared wavefunction plot
ax2.set_xlabel('Position (x)', fontsize=14)
ax2.set_ylabel(r'$|\psi(x,t)|^2$', fontsize=14)
ax2.set_title('Probability Density', fontsize=16)
### Animation settings
# Initialize the wavefunction and its square plots
line_real, = ax1.plot([], [], lw=2)
line_prob, = ax2.plot([], [], lw=2)
# Initialization function for the plot
def init():
line_real.set_data([], [])
line_prob.set_data([], [])
return line_real, line_prob
# Animation function which updates the plot each frame
def animate(i):
t_val = t[i]
psi = psi_total(x, t_val, L, coeffs, n_states)
psi_real = np.real(psi)
psi_squared = np.abs(psi)**2
line_real.set_data(x, psi_real)
line_prob.set_data(x, psi_squared)
return line_real, line_prob
# Create the animation
ani = FuncAnimation(fig, animate, init_func=init, frames=len(t), interval=150, blit=True)
plt.close(fig) # Prevents static display of the last frame
HTML(ani.to_jshtml())Quantum PIB in 3D¶

Figure 3:Particle in a 3D box subject to infinitely high potential walls.
Where we set for particle inside the box and enforce the solutions to be normalized within the confines of the box (electron must be somewhere in the box!)
Consider a particle in a box with side lengths in , in , and in . The potential is zero inside the box and infinite outside it. Again, the potential term can be handled by boundary conditions (i.e., infinite potential implies that the wavefunction must be zero there). The above equation can now be written as:
Note the Laplacian symbol , which concisely denotes the sum of the three second-order derivatives with respect to the spatial variables. We will see this operator in all 3D problems.
In general, when the potential term can be expressed as a sum of terms that depend separately on , , and , the solutions can be written as a product:
By substituting and dividing by , we obtain:
The total energy consists of a sum of three terms, each depending separately on , , and . Thus we can write and separate the equation into three one-dimensional problems:
Thus we find energy quantization due to spatial confinement of the quantum wave function in the , , and dimensions:
Energy is quantized and when , we find that the energy levels can also be degenerate (i.e., the same energy with different values of and ).
In most cases, degeneracy in quantum mechanics arises from symmetry. When , the first excited state has triple degeneracy. When only , the first excited state has double degeneracy.
Source
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # noqa: F401
# -------- Parameters --------
L = 1.0
nx, ny, nz = 1, 2, 3 # quantum numbers
N = 60 # grid points per axis
# -------- Wavefunction on a 3D grid --------
x = np.linspace(0, L, N)
y = np.linspace(0, L, N)
z = np.linspace(0, L, N)
X, Y, Z = np.meshgrid(x, y, z, indexing='ij')
norm = (2.0/np.sqrt(L**3))
psi = norm * np.sin(nx*np.pi*X/L) * np.sin(ny*np.pi*Y/L) * np.sin(nz*np.pi*Z/L)
rho = psi**2 # probability density
# -------- Create illustrative views --------
# 1) Three orthogonal central slices: xy|_{z=L/2}, xz|_{y=L/2}, yz|_{x=L/2}
z_mid = np.argmin(np.abs(z - L/2))
y_mid = np.argmin(np.abs(y - L/2))
x_mid = np.argmin(np.abs(x - L/2))
slice_xy = rho[:, :, z_mid]
slice_xz = rho[:, y_mid, :]
slice_yz = rho[x_mid, :, :]
# 2) "Isosurface-like" point cloud: plot points above a probability threshold
# Choose threshold so that top ~2% of voxels are shown
flat = rho.ravel()
thresh = np.quantile(flat, 0.98)
mask = rho >= thresh
pts = np.column_stack((X[mask], Y[mask], Z[mask]))
# Downsample if there are too many points
max_pts = 8000
if pts.shape[0] > max_pts:
idx = np.random.choice(pts.shape[0], size=max_pts, replace=False)
pts = pts[idx]
# -------- Plot --------
fig = plt.figure(figsize=(12, 9))
# XY slice
ax1 = fig.add_subplot(2, 2, 1)
im1 = ax1.imshow(slice_xy.T, origin='lower', extent=[0, L, 0, L], aspect='equal')
ax1.set_title(rf"$|\psi(x,y,z=L/2)|^2$ (n=({nx},{ny},{nz}))")
ax1.set_xlabel("x")
ax1.set_ylabel("y")
fig.colorbar(im1, ax=ax1, shrink=0.8)
# XZ slice
ax2 = fig.add_subplot(2, 2, 2)
im2 = ax2.imshow(slice_xz.T, origin='lower', extent=[0, L, 0, L], aspect='equal')
ax2.set_title(rf"$|\psi(x,y=L/2,z)|^2$")
ax2.set_xlabel("x")
ax2.set_ylabel("z")
fig.colorbar(im2, ax=ax2, shrink=0.8)
# YZ slice
ax3 = fig.add_subplot(2, 2, 3)
im3 = ax3.imshow(slice_yz.T, origin='lower', extent=[0, L, 0, L], aspect='equal')
ax3.set_title(rf"$|\psi(x=L/2,y,z)|^2$")
ax3.set_xlabel("y")
ax3.set_ylabel("z")
fig.colorbar(im3, ax=ax3, shrink=0.8)
# 3D point cloud (isosurface-like)
ax4 = fig.add_subplot(2, 2, 4, projection='3d')
ax4.scatter(pts[:, 0], pts[:, 1], pts[:, 2], s=2, alpha=0.4)
ax4.set_title("High-probability region (point cloud)")
ax4.set_xlabel("x")
ax4.set_ylabel("y")
ax4.set_zlabel("z")
ax4.set_xlim(0, L); ax4.set_ylim(0, L); ax4.set_zlim(0, L)
plt.suptitle("3D Particle-in-a-Box Orbital: n = (1, 2, 3)", y=0.98)
plt.tight_layout()
plt.show()
Table of energy levels for 3D box
| Quantum Numbers ) | Energy | Degeneracy |
|---|---|---|
| (1,1,1) | 1 | |
| (1,1,2), (1,2,1), (2,1,1) | 3 | |
| (1,1,3), (1,3,1), (3,1,1) | 3 | |
| (1,2,2), (2,1,2), (2,2,1) | 3 | |
| (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1) | 6 | |
| (1,3,3), (3,1,3), (3,3,1) | 3 | |
| (2,2,2) | 1 | |
| (2,2,3), (2,3,2), (3,2,2) | 3 | |
| (2,3,3), (3,2,3), (3,3,2) | 3 | |
| (3,3,3) | 1 | |
| (1,1,4), (1,4,1), (4,1,1) | 3 | |
| (1,2,4), (1,4,2), (2,1,4), (2,4,1), (4,1,2), (4,2,1) | 6 | |
| (1,3,4), (1,4,3), (3,1,4), (3,4,1), (4,1,3), (4,3,1) | 6 | |
| (1,4,4), (4,1,4), (4,4,1) | 3 | |
| (2,2,4), (2,4,2), (4,2,2) | 3 | |
| (2,3,4), (2,4,3), (3,2,4), (3,4,2), (4,2,3), (4,3,2) | 6 | |
| (2,4,4), (4,2,4), (4,4,2) | 3 | |
| (3,3,4), (3,4,3), (4,3,3) | 3 | |
| (3,4,4), (4,3,4), (4,4,3) | 3 | |
| (4,4,4) | 1 |
Note on Computing Average Properties from a Wave Function¶
Because of the probabilistic interpretation of the wave function, average properties can be computed from the wave function. The general formula is
where is any operator. This could be momentum, kinetic energy, and so on. Below are a few problems illustrating how to do such calculations.
To calculate the average position (or expectation value of position) for a particle in a 1D box, follow the steps shown in the example below.
Example: Calculate average (expectation) of position,
1. Wavefunction of the Particle in a 1D Box
The wavefunction for a particle in a 1D box of length with infinite potential walls at and is given by:
where:
is the quantum number (1, 2, 3, ...),
is the length of the box,
is the wavefunction.
2. Expectation Value of Position
The expectation value of the position for a particle is given by:
This integral gives the average position of the particle based on the probability density . For the wavefunction , the probability density is:
3. Set Up the Integral
Substitute into the expression for :
This is the integral you need to solve to find the average position.
4. Solve the Integral
The integral can be simplified using known trigonometric identities. First, use the identity:
So, the integral becomes:
Simplifying:
Now split this into two integrals:
5. Evaluate the Integrals
The first integral is straightforward:
The second integral can be solved using integration by parts or by referring to standard integral tables. It turns out that this integral evaluates to 0 for any integer . Thus:
6. Final Result
Thus, the expectation value of position simplifies to:
7. Interpretation
For any quantum state , the average position of a particle in a 1D box is always:
This result makes sense intuitively because, due to the symmetry of the problem, the particle is equally likely to be found on either side of the box, so its average position is right in the middle of the box at .
Summary¶
To find the average position of a particle in a 1D box for a general wavefunction:
Use the wavefunction ,
Set up the expectation value integral ,
Solve the integral, which results in for all .
Thus, the particle’s average position is always at the midpoint of the box, independent of the quantum number .
Source
# Visual proof that the positive and negative areas cancel:
# ∫_0^L x cos(2 n π x / L) dx = 0
import numpy as np
import matplotlib.pyplot as plt
# Parameters (you can change n or L for other examples)
n = 1
L = 1.0
# Define function
x = np.linspace(0, L, 1500)
f = x * np.cos(2 * np.pi * n * x / L)
# Numerical integral for confirmation
num_int = np.trapezoid(f, x)
# Create plot
plt.figure(figsize=(8, 4.5))
plt.plot(x, f, label=r"$f(x) = x\cos\!\left(\frac{2n\pi x}{L}\right)$")
# Shade positive and negative regions (same default color; annotated for clarity)
pos = f >= 0
neg = f < 0
p = plt.fill_between(x, 0, f, where=pos, alpha=0.3, label="positive area")
q = plt.fill_between(x, 0, f, where=neg, alpha=0.3, label="negative area")
# Add zero line and formatting
plt.axhline(0, linewidth=1)
plt.xlim(0, L)
plt.xlabel("x")
plt.ylabel("f(x)")
plt.title(r"Positive and negative areas cancel: $\int_0^L x\cos\!\left(\frac{2n\pi x}{L}\right)\,dx = 0$")
# Annotate a positive lobe and a negative lobe
# Find a representative positive and negative region to place annotations
if np.any(pos):
idx_pos = np.argmax(f) # near first positive peak
plt.annotate("positive area", xy=(x[idx_pos], f[idx_pos]), xytext=(x[idx_pos]+0.1*L, 0.7*np.max(f)),
arrowprops=dict(arrowstyle="->"))
if np.any(neg):
idx_neg = np.argmin(f) # near first negative through
plt.annotate("negative area", xy=(x[idx_neg], f[idx_neg]), xytext=(x[idx_neg]-0.2*L, 0.7*np.min(f)),
arrowprops=dict(arrowstyle="->"))
# Show numerical check in a small textbox
plt.text(0.02*L, 0.9*np.max(f), f"Numerical integral ≈ {num_int:.2e}")
plt.legend(loc="upper right")
plt.tight_layout()
plt.show()
'vis '
'vis 'Problems¶
Problem 1: Compute probability of finding particle somewhere¶
Compute the probability of observing the particle in a box in the domain .
Solution
Since the square of the wave function is a probability density, we can determine the probability of observing the particle in a particular domain using the relationship
We simply use the above equation together with the normalized particle-in-a-box wave function:
We will use the definite integral of from a table:
Perform a -substitution on the integral above to put it into the table form:
Problem 2: Compute an expectation of ¶
Compute the average of for a particle in a box.
Solution
To compute the average value of , we start by writing the integral expression:
For the particle in a box, we can limit the domain, and thus the bounds of integration, to . We can also set .
Thus, for a particle in a 1D box of size , we get
From an integral table we find that
We use this equation with and get:
This result, combined with the result for , can be used to determine , the standard deviation of the particle’s position:
Problem 3: Compute expectation of energy¶
Compute the average energy of a particle in a box.
Solution
The average energy of the particle in a box is a special case of computing an average quantity. We start by writing out the standard definition of an average computed from a wavefunction:
where is the total energy operator. We know the total energy operator by another symbol, namely . We plug this into the above equation to get:
We now recognize that the particle-in-a-box wavefunctions we are discussing were derived from the Schrödinger equation:
where is a scalar. Thus, for the average energy we get:
The last equality holds because the wave functions are normalized.
Problem 4: Compute expectation of momentum¶
Compute the average momentum for a particle in a box.
Solution
To compute the average momentum of a particle in a 1D box, we start in the usual way:
Recall that the momentum operator in one dimension is given by
We now substitute this into the above equation and solve:
where the last equality can be found in an integral table.
So the average momentum of a particle in a box is zero. This is because it is equally probable for the particle to be moving forward and backward.
Problem 5¶
Consider an electron in superfluid helium (He) where it forms a solvation cavity with a radius of . Calculate the zero-point energy and the energy difference between the ground and first excited states by approximating the electron by a particle in a 3-dimensional box.
Solution
Problem 6: Energy Levels in a 3D Box¶
A particle is confined in a 3D box with side lengths . The energy levels for a particle in this box are given by the formula:
where , , are the quantum numbers associated with the particle’s motion in the -, -, and -directions.
Calculate the energy levels for the quantum states with , , and , , . Are these energy levels degenerate?
Solution
Problem 7: Degeneracy of Energy Levels¶
Consider a particle confined in a cubic box with side lengths . The energy levels are given by the same formula as in Problem 1.
Part 1: Find the degeneracy of the energy level corresponding to the quantum number sum .
Part 2: Write down all the quantum number triplets that correspond to this energy level.
Solution
Part 1: We want to find the quantum numbers that satisfy:
We can check different combinations of , , and :
For , , and :
Other permutations of these quantum numbers will give the same energy:
Part 2: The energy level corresponding to has 6 degenerate states, since the quantum number triplets are , , , , , and .
Problem 8: Degeneracy of the Ground State¶
Part 1: What is the degeneracy of the ground state (the lowest energy state) for a particle in a cubic box?
Part 2: Explain why the ground state does not have degeneracy.
Solution
Part 1: The ground state corresponds to the quantum numbers . The energy for this state is:
There is only one combination of quantum numbers that gives this energy, so the degeneracy of the ground state is 1.
Part 2: The ground state is non-degenerate because there is only one way to assign the quantum numbers . Degeneracy arises when multiple different sets of quantum numbers give the same energy, which is not the case for the ground state.
Problem 9: Higher Energy Degeneracy¶
Consider a particle in a cubic box. The energy levels are quantized as:
Part 1: Find the quantum numbers that give the same energy for the quantum number sum . How many degenerate states correspond to this energy?
Part 2: What is the degeneracy of this energy level?
Solution
Part 1: We want to solve:
Possible combinations of , , and :
, , gives .
, , gives .
Permutations of are:
Part 2: The degeneracy for the energy level corresponding to is 4 (the state and the 3 permutations of ).