A composite Simpson's rule routine estimates .

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π/2cos⁡x dx=1\int_0^{\pi/2}\cos x\,\mathrm{d}x = 1. ((a)) Using step h=π/64h = \pi/64, the Simpson error bound is (b−a)h4max⁡∣f(4)∣/180(b-a)h^4\max|f^{(4)}|/180 with b−a=π/2b-a = \pi/2 and, since f(x)=cos⁡xf(x)=\cos x gives f(4)(x)=cos⁡xf^{(4)}(x)=\cos x, max⁡∣f(4)∣=1\max|f^{(4)}|=1. Compute the tolerance this gives, and say whether a unit test comparing the routine's result with 11 passes it, given that the measured error at this step is 3.2×10−83.2\times10^{-8}. ((b)) The composite rule uses 3333 function evaluations over [0,π/2][0,\pi/2] at this step. A property test checks linearity, that Simpson applied to f+gf+g, with f=cos⁡xf=\cos x and g=exg=e^x, equals the sum of Simpson applied to ff and to gg separately, to relative tolerance 10Mϵmach/210M\epsilon_{\rm mach}/2 with M=33M=33 evaluations and ϵmach=2−52\epsilon_{\rm mach}=2^{-52}. Compute the tolerance, and say whether a measured relative difference of 3.7×10−163.7\times10^{-16} passes it. ((c)) An order-of-accuracy test gives maximum errors e(π/16)=8.30×10−6e(\pi/16) = 8.30\times10^{-6}, e(π/32)=5.17×10−7e(\pi/32) = 5.17\times10^{-7} and e(π/64)=3.23×10−8e(\pi/64) = 3.23\times10^{-8}. Compute the observed order 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)]/\ln 2, and say whether the code is verified against Simpson's formal order pformal=4p_{\rm formal}=4.

Browse the problem library