cmlabs.integrate.test_newton_cotes_error
- cmlabs.integrate.test_newton_cotes_error()[source]
Reach accuracy \(\epsilon\) error for Newton-Cotes rule.
\[\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 Newton-Cotes rule 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 7: Newton-Cotes Rule Error >>> # - f(x) = x - lg(x + 2) >>> # - X_n: [0.5 0.6 0.7 0.8 0.9 1. ] >>> # - Y_n: [0.102 0.185 0.269 0.353 0.438 0.523] >>> # - Coef: [0.066 0.26 0.174 0.174 0.26 0.066] >>> newton_cotes(X_n, Y_n, df['coef']) >>> # - I_n: 0.1556334987504589 >>> # - I_2n: 0.1556334984772168 >>> # |I_n - I_2n|: 2.7324209561641055e-10 >>> # 2.7324209561641055e-10 <= 1e-06 >>> # True
See also