These additional exercises and physics projects accompany Chapter 13
of Computational Physics: From Equations to Simulation.
They explore scaling, stationary points, search reliability,
measurement errors, and the information available in a data set.
The physics projects introduce new models and independent checks.
Use the companion codes or suitable numerical libraries in your
preferred language.
Additional physics projects
The first two projects use optimization to estimate equilibrium
states or energies. The remaining three infer physical parameters
from simulated measurements. Use the stated values for an initial
calculation, then explore the suggested extensions.
1. Equilibrium of coupled nonlinear springs
Level: Intermediate
Objective:
find equilibrium by minimizing energy and verify it through force balance.
Two particles move along a line, with displacements
x1 and x2 from
their reference positions. The first is attached to a wall by
a linear spring. A nonlinear spring connects the particles,
and a constant force F acts on the second particle.
In reduced units, let
U = k1x12/2
+ k2(x2 − x1)2/2
+ β(x2 − x1)4/4
− Fx2.
Use k1 = 10, k2 = 5,
β = 20, and initially F = 1.
Minimize from (0,0), (1,1), and
(−1,2). Derive the gradient, compare methods
with and without supplied derivatives, and report displacements,
energy, force residuals, and evaluation counts.
Validation:
writing d = x2 − x1,
equilibrium requires k1x1 = F
and k2d + βd3 = F.
Independently solve the scalar equation. The default gives
x1 = 0.1 and
x2 ≈ 0.277594729.
Show that the Hessian is positive definite everywhere for these
coefficients, so the energy is strictly convex and has a unique
minimum. All successfully converged minimizations should agree.
Possible extension:
vary F from 0 to 5 and plot the force–displacement
response. Compare with the linear limit β = 0
and use each equilibrium as the next starting guess.
Advanced extension:
set k2 = −5, keeping
β = 20. This models an effective bistable
coupling. Find all roots of −5d + 20d3 = F
and classify their stability. There are three distinct equilibria
for |F| < 0.962250449. Follow a stable local minimum
while slowly sweeping F from −1.2
to 1.2 and back. Use the previous solution as the
starting point and monitor curvature. Compare the resulting
metastable branches and snap-through with a search that selects
the global minimum at every force. Explain why local branch
following can show hysteresis while global minimization does not
give the same loop.
2. A variational estimate for an anharmonic oscillator
Level: Advanced
Objective:
optimize a trial wavefunction and assess the limits of its flexibility.
In units with hbar = m = ω = 1, consider
H = −(1/2)d2/dx2 + x2/2 + λx4,
with λ ≥ 0. Use the normalized Gaussian
trial function
ψa(x) = (πa2)−1/4
exp(−x2/(2a2)),
a > 0.
Evaluate its kinetic and potential energy integrals numerically,
then minimize their sum over a > 0. Start with
λ = 0 and 0.1; repeat for
0.5 and 1. If using a finite integration
interval, enlarge it and refine the quadrature until the optimized
energy is stable. Compare the changes in width and energy with
increasing anharmonicity.
Validation:
derive the Gaussian expectation
E(a) = 1/(4a2) + a2/4 + 3λa4/4
and use it as an independent check. At λ = 0,
the optimum is a = 1, E = 1/2.
At λ = 0.1, expect
a ≈ 0.90491376 and
E ≈ 0.56030737 within this trial family.
This optimized trial energy is an upper bound to the exact
ground-state energy.
Possible extension:
compare with an independent finite-difference eigenvalue calculation.
For λ = 0.1, a converged numerical reference is
E0 ≈ 0.55914633, about
0.21% below the Gaussian estimate. Establish mesh
and domain convergence rather than treating a single discretized
eigenvalue as exact. Separate the error of the trial family from
quadrature and minimization errors.
3. Measuring damping and frequency from a noisy signal
Level: Advanced
Objective:
estimate an oscillation frequency and decay rate while testing
sensitivity to initial guesses and sampling.
x(t) = A exp(−γt) cos(ωt + φ) + c.
Generate 81 equally spaced observations on [0,8]
with A = 1.2, γ = 0.15,
ω = 2π(0.8), φ = 0.3,
and c = 0.1, in consistent reduced units.
Add independent Gaussian noise with standard deviation
0.05. Record the seed and fit all five parameters.
Use A > 0, γ ≥ 0, and
0 < ω < 10. Try starting angular
frequencies 2, 4, 6, 8, with starting values
A = 1, γ = 0.1,
φ = 0, c = 0.
Reduce fitted phases to a common interval when comparing solutions.
Plot the fitted signal and residuals and compare local fits with
a global search followed by local refinement.
Validation:
first fit noise-free data and recover a zero-residual solution
with the stated parameters, allowing phase equivalence modulo
2π. For noisy data, report parameter standard
errors and distinguish angular frequency ω
from frequency ω/(2π). Compare residual
structure across different fitted frequency basins.
Possible extension:
fit only the first two time units or retain every fifth observation.
For every fifth observation starting at t = 0, the
spacing is Δt = 0.5. Derive and identify the
alias ω′ = 2π/Δt − ω
≈ 7.53982237, with φ′ = −φ.
Show that the true and aliased parameters reproduce exactly the
same model samples on this grid, with the same amplitude, damping,
and offset. Both frequencies lie inside the stated bounds, so
fitting these samples alone cannot distinguish them. Explain how
changing the sampling or adding prior frequency information can
resolve the ambiguity.
4. Temperature and calibration from a thermal spectrum
Level: Intermediate
Objective:
infer temperature and an unknown instrument scale from spectral data.
Bλ(λ,T)
= (2hc2/λ5)
/ [exp(hc/(λkBT)) − 1].
Model the measured signal as
s(λ) = q Bλ(λ,T)/Bref,
where q is a dimensionless calibration scale and
Bref = Bλ(1000 nm,3000 K)
is a fixed normalization. Generate 60 equally spaced wavelengths
from 400 to 2000 nm with
T = 3000 K, q = 0.8, and independent
Gaussian errors of standard deviation 0.02 in
the normalized signal.
Convert wavelengths to meters inside the model. Use
h = 6.62607015 × 10−34 J s,
c = 299792458 m/s, and
kB = 1.380649 × 10−23 J/K.
Fit T > 0 and q > 0 from several
guesses, for example (2000,1), (4000,0.5),
and (6000,0.2). Keep Bref
fixed throughout the optimization. Improve parameter scaling by
fitting T/1000 rather than T, or use
a solver’s parameter-scale option, such as SciPy
least_squares
with suitable x_scale values.
Validation:
recover the stated parameters from noise-free data. For noisy
data, compare residuals and parameter covariance using the known
noise level. Repeat with 60 observations restricted to
[1500,2000] nm and compare the temperature–scale
correlation and uncertainty with those from the full spectrum.
Include several seeds before drawing conclusions about precision.
At 400 nm, the true normalized signal is only about
0.0582, compared with noise standard deviation
0.02. Examine the model sensitivities to temperature
and calibration, divided by the noise standard deviation, across
wavelength. Explain why signal amplitude alone does not determine
how much a measurement tells us about temperature.
Possible extension:
add and fit a constant background. Investigate whether the chosen
wavelength range provides enough information to separate temperature,
calibration, and background.
5. Inferring a slit width from a diffraction pattern
Level: Intermediate
Objective:
fit a diffraction model and connect the inferred width with
the positions of intensity minima.
I(θ) = I0[sin(u)/u]2 + B,
u = πa sin(θ)/λ.
This is the far-field intensity pattern of a uniformly illuminated
single slit. Define sin(u)/u = 1 at u = 0.
Take known wavelength λ = 632.8 nm and true
values a = 0.100 mm, I0 = 1,
B = 0.05. Generate 101 equally spaced angles on
[−0.025,0.025] rad, adding independent Gaussian
noise of standard deviation 0.02 in intensity units.
Fit a, I0, and B
with 0.05 ≤ a ≤ 0.20 mm and positive
I0. Use several starting widths and
consistent units. Plot the fitted pattern, its background level,
and the residuals. Use the known noise to estimate parameter
standard errors and repeat for several seeds.
Validation:
the first minima satisfy a sin(θ) = ±λ.
For the true width, their angles are approximately
±0.00632804 rad. Compare a width estimate
based on the minima with the full-curve fit. Check noise-free
recovery and handle the u = 0 limit explicitly;
the specified angle grid includes θ = 0.
Possible extension:
introduce a small unknown angular offset and fit it as a fourth
parameter. Compare fits using the entire pattern and only the
central peak, with attention to parameter correlations.