cmlabs.integrate.test_simpsonc_error

cmlabs.integrate.test_simpsonc_error()[source]

Reach accuracy \(\epsilon\) error for Simpson’s rule (cubic).

\[\begin{split}\begin{gather} |I_n - I_{2n}| \leq \epsilon, \\ |I_{2n} - I_{4n}| \leq \epsilon, \\ \ldots \\ |I_{2^k n} - I_{2^{k+1} n}| \leq \epsilon, \\ \end{gather}\end{split}\]

where \(I_n\) is the integral of the function \(f(x)\) over the interval \([a, b]\) using Simpson’s rule (cubic) with \(n\) subintervals, and \(\epsilon\) is the desired accuracy.

Notes

\[\begin{split}\begin{gather} \int_a^b f(x) \, dx = \int_{0.5}^{1} x - \log_{10}(x + 2) \, dx \\ = \frac{1\ln{10} + 20\ln{5} - 24\ln{3} - 20\ln{2} + 4}{8\ln{10}} \\ \approx 0.1556335 \end{gather}\end{split}\]

Results

>>> # Test 5: Simpson's Rule (Cubic) Error
>>> # - f(x) = x - lg(x + 2)
>>> # - X_n:  [0.5   0.667 0.833 1.   ]
>>> # - Y_1:  [0.102 0.241 0.381 0.523]
>>> # - X_2n:  [0.5   0.583 0.667 ... 0.833 0.917 1.   ]
>>> # - Y_2n:  [0.102 0.171 0.241 ... 0.381 0.452 0.523]
>>> simpsonc(X_n, Y_n)
>>> # - I_n:  0.15563372042547285
>>> simpsonc(X_2n, Y_2n)
>>> # - I_2n:  0.15563351252747326
>>> # |I_n - I_2n|:  2.0789799959342048e-07
>>> # 2.0789799959342048e-07 <= 0.0001
>>> # True

See also

simpsonc