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
A composite Simpson's rule routine estimates ∫0π/2cosxdx=1.
((a)) Using step h=π/64, the Simpson error bound is (b−a)h4max∣f(4)∣/180 with b−a=π/2 and, since f(x)=cosx gives f(4)(x)=cosx, max∣f(4)∣=1. Compute the tolerance this gives, and say whether a unit test comparing the routine's result with 1 passes it, given that the measured error at this step is 3.2×10−8.
((b)) The composite rule uses 33 function evaluations over [0,π/2] at this step. A property test checks linearity, that Simpson applied to f+g, with f=cosx and g=ex, equals the sum of Simpson applied to f and to g separately, to relative tolerance 10Mϵmach/2 with M=33 evaluations and ϵmach=2−52. Compute the tolerance, and say whether a measured relative difference of 3.7×10−16 passes it.
((c)) An order-of-accuracy test gives maximum errors e(π/16)=8.30×10−6, e(π/32)=5.17×10−7 and e(π/64)=3.23×10−8. Compute the observed order p^ from each consecutive pair using p^=ln[e(h)/e(h/2)]/ln2, and say whether the code is verified against Simpson's formal order pformal=4.