I'm trying to compute $\int_0^4 x^2 dx$ using 2-point Gaussian quadrature. This should give an exact result since for 2 points, we can exactly handle polynomials of degree 2*2-1=3.

By the usual technique, we must first transform this integral to the range $[-1,1]$. This is done using the formula (see change of interval section on this Wikipedia page: https://en.wikipedia.org/wiki/Gaussian_quadrature) by

$\int_0^4 f(x) dx = \frac{4-0}{2} \int_{-1}^1 f(\frac{4-0}{2}x + \frac{4+0}{2}) dx = 2 \int_{-1}^1 f(2x+2) dx$,

and for my function $f(x)=x^2$, this gives

$\int_0^4 x^2 dx = \int_{-1}^1 (2x+2)^2 dx$.

Now 2-point Gaussian quadrature tells me that $\int_{-1}^1 f(x) dx = f(\frac{1}{\sqrt{3}}) + f(-\frac{1}{\sqrt{3}})$ (these weights and points are listed in the first table on the Wikipedia page I linked to above). Now, if I actually evaluate this, I get

$\int_0^4 x^2 dx = \int_{-1}^1 (2x+2)^2 dx = (\frac{2}{\sqrt{3}} + 2)^2 + (-\frac{2}{\sqrt{3}} + 2)^2 = \frac{32}{\sqrt{3}}$.

However, the original integral gives $\int_0^4 x^2 = \frac{x^3}{3}|_0^4 = \frac{256}{3}$ and so my Gaussian quadrature approach is clearly miles off of the actual answer! Given that $x^2$ has degree $\leq 3$, a 2-point Gaussian quadrature should give the exact answer and so my question is basically what have I done wrong?!?!?

Thanks.

• Just out of curiousity.. can I ask why you're using an approximation method on an elementary function? Practice, perhaps? I only ask because when utilizing Gaussian quadrature approximation, you risk the chance of generating an error.. one that is proportional to the function's $2n^{th}$ derivative, where $n$ is the number of points. Just something to keep in mind if you attempt higher-ordered functions. – Charles Jul 31 '17 at 15:08

First off, you forgot the factor of $2$ in the transformation, i.e.
$$\int_{0}^{4} x^2 dx = 2\int_{-1}^{1}(2x+2)^2 dx$$
$$\left(\frac{2}{\sqrt{3}} + 2\right)^2 + \left(-\frac{2}{\sqrt{3}} + 2\right)^2 = \frac{32}{3}$$
Finally, $4^3 = 64$. If you correct all your mistakes you'll get the correct answer of $64/3$ using both methods.