Three routines from earlier chapters are tested.

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=500N=500 diagonal entries of a matrix, each entry equal to 0.10.1, so the exact trace is 5050. A unit test compares the routine's result with 5050 using the backward-error tolerance Nϵmach/2N\epsilon_{\rm mach}/2 for a sequential floating-point sum, with ϵmach=2−52\epsilon_{\rm mach}=2^{-52}. Compute the relative tolerance, and say whether the test passes given a measured relative error of 8.8×10−158.8\times10^{-15}. ((b)) An eigen-decomposition routine on a symmetric n=100n=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/210n\epsilon_{\rm mach}/2. Compute it, and say whether a measured relative deviation of 4×10−154\times10^{-15} passes. ((c)) A routine meant to return the central-difference estimate of d(sin⁡x)/dx\mathrm{d}(\sin x)/\mathrm{d}x at x=1x=1, of formal order pformal=2p_{\rm formal}=2, gives errors e(0.1)=4.29×10−2e(0.1)=4.29\times10^{-2}, e(0.05)=2.13×10−2e(0.05)=2.13\times10^{-2} and e(0.025)=1.06×10−2e(0.025)=1.06\times10^{-2}. 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, say whether the routine is verified, and name a coding slip consistent with the observed order.

Browse the problem library