Gaussian rule with 3 nodes:
In the quadrature formula
$$ \int_{a}^{b}f(x)dx\approx \omega_{0}f(x_{0})+\omega_{1}f(x_{1})+\cdots +\omega_{N}f(x_{N}) $$Is it possible to find the weights $\omega_i$ and the nodes $x_i$ so that the degree of precision of the formula is as high as possible? Yes, but then the nodes will not be equally spaced and these formulas are called Gauss-Legendre formulas. The nodes for the interval $[-1,1]$ will be the zeros of the Legendre polynomials
Once we have the nodes, the way to deduce the corresponding quadrature formula could be the same as using equispaced nodes: if $P_{N}$ is the polynomial that interpolates $f$ in the Legendre nodes $x_{0},x_{1},...,x_{N} \in \left[ -1,1\right]$ and
$$ \int_{-1}^{1}f(x)\,dx\approx \int_{-1}^{1}P_N(x)\,dx=\omega_{0}\,f(x_{0})+\omega_{1}\,f(x_{1})+\cdots +\omega_{n}\,f(x_{N}) $$This formula can be easily adapted for another interval $[a,b].$
For $[-1,1]$ the weights and the nodes are
Thus, for instance
Gaussian rule with one node
$$ \int_{-1}^{1}f(x)\,dx\approx 2\;f(0) $$Gaussian rule with 2 nodes
$$ \int_{-1}^{1}f(x)\,dx\approx f(-0.5774)+f(0.5774) $$Gaussian rule with 3 nodes
$$ \int_{-1}^{1}f(x)\,dx\approx 0.5556\;f(-0.7746)+0.8889\;f(0)+ 0.5556\;f(0.7746) $$And so on.
This can be generalized for any interval $[a,b]$ swapping $x_i$ with $y_i$ following
$$y_i=\frac{b-a}{2}x_i+\frac{a+b}{2}$$And the quadrature formula is now
$$ \int_{a}^{b}f(x)dx\approx\frac{b-a}{2}\left( \omega_{0}\;f(y_{0})+\omega_{1}\;f(y_{1})+\cdots +\omega_{n}\;f(y_{n})\right) $$Compute $$\int_{0}^{3}e^{-\frac{x^{2}}{2}}dx$$ using the gaussian rule of 3 nodes:
$$\int_{-1}^{1}f(x)\:dx\approx\frac{5}{9}\,f\left(-\sqrt{\dfrac{3}{5}}\right)+\frac{8}{9}\,f\left(0\right)+\frac{5}{9}\,f\left(\sqrt{\dfrac{3}{5}}\right)$$We want to change variable that takes us from the interval $[0,3]$ to the interval where the formula is defined, that is, $[-1,1]$.
If we perform a linear change of variable
$$x = m\,t +n,$$that if $x = 0$, then $t = -1$ then
$$0 = -m+n.$$And if $x = 3$, then $t = 1$ then
$$3 = m+n.$$Adding these two equations
$$3 = 2n \quad \fbox{$n = \dfrac{3}{2}$}$$We multiply the first equation by $-1$
$$0 = m-n \quad 3 = m+n$$And we add the equations again
$$3 = 2m \quad \fbox{$m = \dfrac{3}{2}$}$$Thus, the solution of the linear system is
$$m = \frac{3}{2}\quad n = \frac{3}{2}$$And the change of variable is
$$x=\frac{3}{2}\,t+\frac{3}{2}\qquad dx=\frac{3}{2}dt.$$As our formula was
$$\int_{-1}^{1}f(x)\:dx\approx\frac{5}{9}\,f\left(-\sqrt{\dfrac{3}{5}}\right)+\frac{8}{9}\,f\left(0\right)+\frac{5}{9}\,f\left(\sqrt{\dfrac{3}{5}}\right)$$And since the variable change forced the interval $[0,3]$ to transform into the interval $[-1,1]$
. $$\approx\frac{3}{2}\left[\frac{5}{9}\,f\left(-\frac{3}{2}\sqrt{\dfrac{3}{5}}+\frac{3}{2}\right)+\frac{8}{9}\,f\left(\frac{3}{2}\right)+\frac{5}{9}\,f\left(\frac{3}{2}\sqrt{\dfrac{3}{5}}+\frac{3}{2}\right)\right]= $$
. $$ =\frac{3}{2}\left[\frac{5}{9}\,f(0.3381)+\frac{8}{9}\,f(1.5)+\frac{5}{9}\,f(2.6619)\right]=$$
and taking into account that $f(x)=e^{-\frac{x^{2}}{2}}$ . $$=\frac{3}{2}\left[\frac{5}{9}\,(0.9444)+\frac{8}{9}\,(0.3246)+\frac{5}{9}\,(0.02893)\right]=1.24402 $$
In fact
Ie = 1.24993044474155
Ia = 1.24401686205204
Error = 0.00591358268951
The nodes of Gaussian formulas are chosen in such a way the precision of the formula is maximized.
In general, a Gauss-Legendre formula of $n$ points will be exact for polynomial functions of degree less than or equal to $2n-1$. Therefore, with one node the precision is $1$, with two nodes the precision is $3$, and with three nodes the precision is $5$.
If we compare the Gaussian formulas with the Newton-Cotes formulas with the same nodes