# Derive the Newton-cotes formula for $\int f(x) dx$ using nodes $o, \frac13, \frac23, \1$.

Can someone please let me know if I am on the right track here. Obviously, I still need to perform the integrations as well as evaluate the integrations(from 0 to 1) to determine the coefficients. What I gather from my notes, and the text book, this is the procedure for equally spaced nodes but I'm not sure as there are several methods (trap. rule, Simpson's rule, composite trap. rule, etc. Any advice would be greatly appreciated!!

$$\int^1_0 p_3(x)dx = f(a) \int^1_0\frac{(x-\frac13)(x-\frac23)(x-1)}{(0-\frac13)(0-\frac23)(0-1)}dx + f(b)\int^1_0\frac{(x)(x-\frac23)(x-1)}{(\frac13-0)(\frac13-\frac23)(\frac13-1)} + f(c)\int^1_0\frac{(x)(x-\frac13)(x-1)}{(\frac23-0)(\frac23-\frac13)(\frac23-1)} + f(d)\int^1_0\frac{(x)(x-\frac13)(x-\frac23)}{(1-0)(1-\frac13)(1-\frac23)}$$

You can crunch those integrals, or you can reason that the approximation must be exact for $$f = 1, x, x^2, x^3$$ and get a linear system for the weights: Write the approximation as $$\int_{0}^{1}p_3(x)\,dx = \sum_{i = 1}^{4}w_if(x_i)$$ where $$x_1 = 0$$, $$x_2 = 1/3$$, $$x_3 = 2/3$$, $$x_4 = 1$$ and the $$w_i$$ are to be determined. The approximation must be exact for $$f = 1, x, x^2, x^3$$, so that gives the system of equations $$\begin{bmatrix} 1 & 1 & 1 & 1 \\ x_1 & x_2 & x_3 & x_4 \\ x_1^2 & x_2^2 & x_3^2 & x_4^2 \\ x_1^3 & x_2^3 & x_3^3 & x_4^3 \\ \end{bmatrix} \begin{bmatrix} w_1 \\ w_2 \\ w_3 \\ w_4 \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 1/2 \\ 1/3 \\ 1/4 \\ \end{bmatrix}$$ which you can solve to find the $$w_i$$. Both your approach and this approach can generate the weights for any choice of distinct nodes; there is nothing special about equally spaced nodes.
Edit on why it should be exact on $$1, x, x^2, x^3$$:
The integration method is based on calculating the interpolation polynomial $$p_3(x)$$ and integrating it. When you interpolate $$4$$ points from a function $$f$$ that is a polynomial of degree $$3$$ or less, the interpolation polynomial $$p_3$$ matches $$f$$ identically (by uniqueness of the interpolating polynomial).
One way to see why exactness makes the approximation good is to consider the approximation on a small interval $$[-h, h]$$: $$\int_{-h}^{h}f(x)\,dx \approx 2h\sum_{i = 1}^{N}w_if(x_ih).$$ Define the error in the approximation for a function $$f$$ as $$E(f) := \int_{-h}^{h}f(x)\,dx - 2h\sum_{i = 1}^{N}w_if(x_ih)$$ Note that $$E$$ is a linear map. Writing $$f$$ as a Taylor series around $$0$$ gives \begin{align} E(f) &= E\left(\sum_{n = 0}^{\infty}\frac{f^{(n)}(0)}{n!}x^n\right) \\ &= \sum_{n = 0}^{\infty}\frac{f^{(n)}(0)}{n!}E(x^n) \end{align} You can verify that $$E(x^n) = O(h^{n + 1})$$. Hence if $$k$$ is the smallest integer for which $$E(x^k) \neq 0$$, then the error is $$E(f) = \frac{f^{(k)}(0)}{k!}E(x^k) + O(h^{k + 2}) = O(h^{k + 1}).$$ So exactness on polynomials increases the accuracy of the approximation on all (smooth enough) functions.