Newton-Cotes formula is a general class of formulas that estimate the integral of a function with the integral of a Lagrange interpolation polynomial of the function.
Say we want to estimate \(\int_{a}^{b}f(x)\,\mathrm{d}x\).
Let \(h=\frac{b-a}{n}, x_i=a+ih, f_i=f(x_i),\quad i=0,1,2,\cdots,n\).
The result polynomial of Lagrange interpolation will be
\[g(x)=\sum_{i=0}^{n}{f_i\cdot l_i(x)}, l_i(x)=\prod_{j=0,j\neq i}^{n}{\frac{x-x_j}{x_i-x_j}}.
\]
We estimate the integral of \(f\) with that of \(g\):
\[\int_{a}^{b}{f(x)\,\mathrm{d}x}\approx \int_{a}^{b}{g(x)\,\mathrm{d}x}=
\sum_{i=0}^{n}({f_i\cdot \int_{a}^{b}{l_i(x)\,\mathrm{d}x}}).\]
Now the problem boils down to the integral of \(l_i\).
By transformation we can show that \(\int_{a}^{b}{l_i(x)\,\mathrm{d}x}=(b-a)\int_{0}^{1}{l_i(x)\,\mathrm{d}x}\).
(Note: the \(l_i\)s are based on different interpolation nodes.)
Let \(\alpha_{i}=\int_{0}^{1}{l_i(x)\,\mathrm{d}x}\) and \(t_i=\frac{i}{n},\quad i=0,1,2,\cdots,n\).
Then
\[\int_{0}^{1}{x^k\,\mathrm{d}x} \approx \sum_{i=0}^{n}{\alpha_{i}\cdot {t_i}^k}=\frac{1}{k+1},\quad k=0,1,2,\cdots,n.
\]
Namely
\[\begin{bmatrix}
1 & 1 & 1 & \cdots & 1 \\
t_0 & t_1 & t_2 & \cdots & t_n \\
t_0^2 & t_1^2 & t_2^2 & \cdots & t_n^2 \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
t_0^n & t_1^n & t_2^n & \cdots & t_n^n
\end{bmatrix}
\begin{bmatrix}
\alpha_0 \\[2pt]
\alpha_1 \\[2pt]
\alpha_2 \\[2pt]
\vdots \\[2pt]
\alpha_n
\end{bmatrix}
=
\begin{bmatrix}
\frac{1}{1} \\[4pt]
\frac{1}{2} \\[4pt]
\frac{1}{3} \\[4pt]
\vdots \\[4pt]
\frac{1}{n+1}
\end{bmatrix}.
\]
Solving this system gives \(\alpha_{i}\).
Newton-Cotes formula is then
\[\int_{a}^{b}{f(x)\,\mathrm{d}x}\approx (b-a)\sum_{i=0}^{n}{\alpha_{i}f_{i}}.
\]
Appendix I. For Newton-Cotes formulas, the degree of exactness is:
\[\text{exactness} =
\begin{cases}
n+1, & \text{if $n$ is even}, \\
n, & \text{if $n$ is odd}.
\end{cases}
\]
Appendix II. Newton-Cotes formulas for \(n=1,2,3\).
\[\int_a^b f(x)\,\mathrm{d}x \approx \frac{b-a}{2} \,[f_0 + f_1]
\]
\[\int_a^b f(x)\,\mathrm{d}x \approx \frac{b-a}{6} \,[f_0 + 4f_1 + f_2]
\]
\[\int_a^b f(x)\,\mathrm{d}x \approx \frac{b-a}{8} \,[f_0 + 3f_1 + 3f_2 + f_3]
\]