import numpy as np
import plotly.graph_objects as go
try:
import executable_engineering as exe
except ImportError:
%pip install -q executable_engineering
import executable_engineering as exeSubdividing into Panel Approximations¶
The Newton-Cotes formulae approximate the integrand by replacing it with a low-degree polynomial over subdivided intervals.
For example, a function can be subdivided into a series of increasingly narrower rectangular panels.
Since we are performing a summation over subdivisions, there is no need for continuity between higher derivatives across panel edges; each element can be integrated separately and the results added up.
fig = exe.plot_riemann_sum(np.sin, 0, np.pi, n=8, rule="left", title="Newton-Cotes Panel Discretization (n=8)")
fig.show()Error Convergence as ¶
It is easy to see that as the step size , the number of boxes , and the approximation approaches the analytic integral.
fig = exe.plot_riemann_sum(np.sin, 0, np.pi, n=24, rule="midpoint", title="Fine Panel Refinement (n=24)")
fig.show()Engineering Use Cases¶
These formulae are valid for both the cases where the function is given analytically and where only discrete sample points are available.
However, when analytical functions are known, adaptive step-size methods and Gaussian quadrature are typically far more computationally efficient than fixed-step Newton-Cotes rules.