PHYSICS · Multi-part · Fermi University Physics · Computational Physics · Scientific programming for physicists · Research software practice, verification and validation
Scientific Computing for Physicists, Ch Is the equation solved right? Testing, debugging and code verification
Problem
Three routines from earlier chapters are tested.
((a)) A routine sums the N=500 diagonal entries of a matrix, each entry equal to 0.1, so the exact trace is 50. A unit test compares the routine's result with 50 using the backward-error tolerance Nϵmach/2 for a sequential floating-point sum, with ϵmach=2−52. Compute the relative tolerance, and say whether the test passes given a measured relative error of 8.8×10−15.
((b)) An eigen-decomposition routine on a symmetric n=100 matrix is tested for the invariant that the sum of the computed eigenvalues equals the trace, checked again after the matrix is transformed by a random orthogonal similarity transform (a rotation of the basis, which leaves the trace unchanged). The property-test tolerance is taken as 10nϵmach/2. Compute it, and say whether a measured relative deviation of 4×10−15 passes.
((c)) A routine meant to return the central-difference estimate of d(sinx)/dx at x=1, of formal order pformal=2, gives errors e(0.1)=4.29×10−2, e(0.05)=2.13×10−2 and e(0.025)=1.06×10−2. Compute p^ from each consecutive pair using p^=ln[e(h)/e(h/2)]/ln2, say whether the routine is verified, and name a coding slip consistent with the observed order.