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.

Particle in a Box

Classical vs Quantum particle in a box

PIB-wiki

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 ψn(x)\psi_n(x). States B, C, D are the n=1,2,3n=1,2,3 eigenfunctions of the Hamiltonian, while E and F are not.

Solving the Schrödinger Equation for the Particle in a Box (PIB)

Particle in a box

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.

V(x)={x=0 or x=L00<x<LV(x) = \begin{cases} \infty & x = 0 \text{ or } x = L \\ 0 & 0 < x < L \end{cases}
ψ(0)=ψ(L)=0\psi(0) = \psi(L) = 0
H^=K^=22md2dx2\hat{H} = \hat{K} = -\frac{\hbar^2}{2m} \frac{d^2}{dx^2}
H^ψ(x)=Eψ(x)\hat{H} \psi(x) = E \psi(x)
22md2dx2ψ(x)=Eψ(x)-\frac{\hbar^2}{2m} \frac{d^2}{dx^2} \psi(x) = E \psi(x)
ψ(x)=k2ψ(x)\psi''(x) = -k^2 \psi(x)
k2=2mE2k^2 = \frac{2mE}{\hbar^2}

Solution and Boundary Conditions

ψ(x)=k2ψ(x)\psi''(x) = -k^2 \psi(x)
ψ(x)=c1eikx+c2eikx=Acos(kx)+Bsin(kx)\psi(x) = c_1 e^{ikx} + c_2 e^{-ikx} = A \cos(kx) + B \sin(kx)
ψ(x)=Bsin(kx)\psi(x) = B \sin(kx)
Bsin(kL)=0B \sin(kL) = 0
kL=nπork=nπLkL = n\pi \quad \text{or} \quad k = \frac{n\pi}{L}
ψ(x)=Bsin(nπLx)\psi(x) = B \sin\left(\frac{n\pi}{L}x\right)
En=n2h28mL2E_n = \frac{n^2 h^2}{8mL^2}

Wavefunctions Must Be Normalized

$$ \int_0^L \psi_n(x)^2 , dx = 1

$$

Bn20Lsin2(nπxL)dx=Bn220L[1cos(2nπxL)]dx=1B_n^2 \int_0^L \sin^2\left(\frac{n\pi x}{L}\right) dx = \frac{B_n^2}{2} \int_0^L \left[ 1 - \cos\left(\frac{2n\pi x}{L}\right) \right] dx =1
Bn22L=1\frac{B_n^2}{2} \cdot L = 1
Bn=2LB_n = \sqrt{\frac{2}{L}}

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()
<Figure size 800x600 with 2 Axes>

Discrete energy levels and zero point energy

Quantum particles are never at rest

E1=h2/8mL2E_1 = h^2/8mL^2
En+1En=(2n+1)h28mL2E_{n+1} - E_n = (2n+1)\frac{h^2}{8mL^2}

Increasing Box size leads to more classical behavior

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()
<Figure size 1200x500 with 2 Axes>

Non-uniform probabilities and nodes

  1. Nodes imply zero probability to find an electron in the box.

    • ψn2=0|\psi_n|^2=0 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.

  2. There are n1n-1 nodes for quantum state nn

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$")
<Figure size 1400x400 with 3 Axes>

On time-dependence

Pure states

ψn(x,t)2=ψn(x,t)ψn(x,t)=ψ(x)eiEnt/ψ(x)e+Ent/=ψ(x)2|\psi_n(x,t)|^2 = \psi_n(x,t)^{*}\cdot\psi_n(x,t) = \psi(x)e^{-iE_nt/\hbar}\cdot \psi(x)e^{+E_nt/\hbar} = |\psi(x)|^2
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())
Loading...

Mixed states

ψ(x,t)=c1ψ1(x)eiE1t/+c2ψ2eiE2t/\psi(x,t) = c_1 \psi_1(x) e^{-iE_1t/\hbar} +c_2 \psi_2 e^{-iE_2t/\hbar}
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())
Loading...

Quantum PIB in 3D

pib1

Figure 3:Particle in a 3D box subject to infinitely high potential walls.

H^ψ(x,y,z)=Eψ(x,y,z)\hat{H}\psi(x,y,z) = E\psi(x,y,z)
22m(2ψx2+2ψy2+2ψz2)=Eψ{-\frac{\hbar^2}{2m}\left(\frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} + \frac{\partial^2\psi}{\partial z^2}\right) = E\psi}
ψ(x,y,z)2dxdydz=1{\int\limits_{-\infty}^{\infty}\int\limits_{-\infty}^{\infty}\int\limits_{-\infty}^{\infty}\left|\psi(x,y,z)\right|^2dxdydz = 1}
22mΔψ=Eψwith ψ(a,y,z)=ψ(x,b,z)=ψ(x,y,c)=0and ψ(0,y,z)=ψ(x,0,z)=ψ(x,y,0)=0{-\frac{\hbar^2}{2m}\Delta\psi = E\psi} \\ {\textnormal{with }\psi(a,y,z) = \psi(x,b,z) = \psi(x,y,c) = 0} \\ {\textnormal{and }\psi(0,y,z) = \psi(x,0,z) = \psi(x,y,0) = 0}
ψ(x,y,z)=X(x)Y(y)Z(z){\psi(x,y,z) = X(x)Y(y)Z(z)}
22m[1X(x)d2X(x)dx2+1Y(y)d2Y(y)dy2+1Z(z)d2Z(z)dz2]=E{-\frac{\hbar^2}{2m}\left[\frac{1}{X(x)}\frac{d^2X(x)}{dx^2} + \frac{1}{Y(y)}\frac{d^2Y(y)}{dy^2} + \frac{1}{Z(z)}\frac{d^2Z(z)}{dz^2}\right] = E}
22m[1X(x)d2X(x)dx2]=Ex with X(0)=X(a)=022m[1Y(y)d2Y(y)dy2]=Ey with Y(0)=Y(b)=022m[1Z(z)d2Z(z)dz2]=Ez with Z(0)=Z(c)=0{-\frac{\hbar^2}{2m}\left[\frac{1}{X(x)}\frac{d^2X(x)}{dx^2}\right] = E_x\textnormal{ with }X(0) = X(a) = 0}\\ {-\frac{\hbar^2}{2m}\left[\frac{1}{Y(y)}\frac{d^2Y(y)}{dy^2}\right] = E_y\textnormal{ with }Y(0) = Y(b) = 0}\\ {-\frac{\hbar^2}{2m}\left[\frac{1}{Z(z)}\frac{d^2Z(z)}{dz^2}\right] = E_z\textnormal{ with }Z(0) = Z(c) = 0}
X(x)=2asin(nxπxa)Y(y)=2bsin(nyπyb)Z(z)=2csin(nzπzc){X(x) = \sqrt{\frac{2}{a}}\sin\left(\frac{n_x\pi x}{a}\right)}\\ {Y(y) = \sqrt{\frac{2}{b}}\sin\left(\frac{n_y\pi y}{b}\right)}\\ {Z(z) = \sqrt{\frac{2}{c}}\sin\left(\frac{n_z\pi z}{c}\right)}
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()
<Figure size 1200x900 with 7 Axes>

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

A=ψ(x)A^ψ(x)dx\langle A \rangle = \int \psi^*(x)\hat{A}\psi(x)dx

where A^\hat{A} 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.

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 '
<Figure size 800x450 with 1 Axes>
'vis '

Problems

Problem 1: Compute probability of finding particle somewhere

Compute the probability of observing the particle in a box in the domain a3x2a3\frac{a}{3} \leq x \leq \frac{2a}{3}.

Problem 2: Compute an expectation of x2x^2

Compute the average of x2x^2 for a particle in a box.

Problem 3: Compute expectation of energy

Compute the average energy of a particle in a box.

Problem 4: Compute expectation of momentum

Compute the average momentum for a particle in a box.

Problem 5

Consider an electron in superfluid helium (4^4He) where it forms a solvation cavity with a radius of 18A˚18 \text{Å}. 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.

Problem 6: Energy Levels in a 3D Box

A particle is confined in a 3D box with side lengths Lx=Ly=Lz=LL_x = L_y = L_z = L. The energy levels for a particle in this box are given by the formula:

Enx,ny,nz=2π22mL2(nx2+ny2+nz2)E_{n_x, n_y, n_z} = \frac{\hbar^2 \pi^2}{2mL^2} \left( n_x^2 + n_y^2 + n_z^2 \right)

where nxn_x, nyn_y, nzn_z are the quantum numbers associated with the particle’s motion in the xx-, yy-, and zz-directions.

Calculate the energy levels for the quantum states with nx=1n_x = 1, ny=1n_y = 1, nz=2n_z = 2 and nx=2n_x = 2, ny=2n_y = 2, nz=1n_z = 1. Are these energy levels degenerate?

Problem 7: Degeneracy of Energy Levels

Consider a particle confined in a cubic box with side lengths Lx=Ly=Lz=LL_x = L_y = L_z = L. The energy levels are given by the same formula as in Problem 1.

Problem 8: Degeneracy of the Ground State

Problem 9: Higher Energy Degeneracy

Consider a particle in a cubic box. The energy levels are quantized as:

Enx,ny,nz=2π22mL2(nx2+ny2+nz2)E_{n_x, n_y, n_z} = \frac{\hbar^2 \pi^2}{2mL^2} \left( n_x^2 + n_y^2 + n_z^2 \right)