cmlabs.integrate.newton_cotes

cmlabs.integrate.newton_cotes(xvals, yvals, coef)[source]

Composite Newton-Cotes method for numerical integration.

\[\begin{split}\begin{gather} I_n = (b - a) \cdot \sum_{i=0}^{n} c_i f(x_i) \\ \end{gather}\end{split}\]
Parameters:
  • xvals (array_like, 1-D) – The sorted x-coordinates of the data points.

  • yvals (array_like, 1-D) – The y-coordinates of the data points, i.e., \(f(x)\).

  • coef (array_like, 1-D) – The coefficients of the Newton-Cotes formula.

Returns:

The approximate value of the integral.

Return type:

float

Notes

The Newton-Cotes method approximates the area under the curve by dividing it into polynomials. The height of each polynomial is determined by the function value at the endpoints and midpoints of the interval.

\(\textit{coef}\) is the coefficients of the Newton-Cotes formula. The coefficients are determined by the order of the polynomial used in the approximation. The coefficients are usually derived from the Lagrange interpolation polynomial.