An Euler-Cromer routine integrates a simple harmonic oscillator with , ,

PHYSICS · Multi-part · Fermi University Physics · Mathematical Methods for Physics · Computational Physics · Research software practice, verification and validation

Scientific Computing for Physicists, Ch Is the equation solved right? Testing, debugging and code verification

Problem

An Euler-Cromer routine integrates a simple harmonic oscillator with ω=1 rad s−1\omega = 1\,\mathrm{rad\,s^{-1}}, x(0)=1 mx(0)=1\,\mathrm{m}, v(0)=0 m s−1v(0)=0\,\mathrm{m\,s^{-1}}, exact solution x(t)=cos⁡(ωt)x(t)=\cos(\omega t). ((a)) A unit test runs the routine to t=1 st=1\,\mathrm{s} with h=0.001 sh=0.001\,\mathrm{s}. State the exact value x(1)=cos⁡(1)x(1)=\cos(1) to six significant figures, and say whether the test passes a tolerance of 2×10−3 m2\times10^{-3}\,\mathrm{m}, given a measured error of 4.2×10−4 m4.2\times10^{-4}\,\mathrm{m} at this step. ((b)) The Euler-Cromer map is area-preserving: the Jacobian determinant of one step is exactly 11 for any hh. A property test computes this determinant numerically, by LU factorisation at h=0.01 sh=0.01\,\mathrm{s}, and checks ∣det⁡−1∣|\det - 1| against tolerance 5ϵmach5\epsilon_{\rm mach}, with ϵmach=2−52\epsilon_{\rm mach}=2^{-52}. Compute the tolerance, and say whether a measured value of 1.1×10−161.1\times10^{-16} passes it. ((c)) An order-of-accuracy test gives maximum errors e(0.02)=8.43×10−3 me(0.02)=8.43\times10^{-3}\,\mathrm{m}, e(0.01)=4.21×10−3 me(0.01)=4.21\times10^{-3}\,\mathrm{m} and e(0.005)=2.10×10−3 me(0.005)=2.10\times10^{-3}\,\mathrm{m}. Compute p^\hat{p} from each consecutive pair using p^=ln⁡[e(h)/e(h/2)]/ln⁡2\hat{p}=\ln[e(h)/e(h/2)]/\ln2, and say whether the code is verified against Euler-Cromer's formal order pformal=1p_{\rm formal}=1.

Browse the problem library