# When is trapezoidal rule better than Gaussian quadrature?

I have used the trapezoidal rule to evaluate the integral $$\int_{-1}^1 |x| \, dx$$ and it gives an aproximation without any error (the exact solution: $1$). However, when I use Gauss–Chebyshev or Gauss–Legendre quadrature, I have an error in the approximation. Why? I thought Gauss quadrature was always more precise than the trapezoidal rule.

• Gauss quadrature is best when there are polynomials of degree $2n-1$ but however, choosing a particular method depends on the problem. – tien lee May 30 '18 at 16:53
• @tienlee When is it better to use each method? Here the derivative of $|x|$ (on all points but $x=0$ is the same ($-1$ and $1$). Therefore taking equidistant nodes is better than taking the chebyshev nodes which are more focused on the sides of the interval $[-1,1]$. This is just what my intuition says, I could not prove it – John Keeper May 30 '18 at 17:00
• Do you get the same relation between errors if the integration interval is not symmetric, if you integrate from $-0.9$ to $1.1$? – LutzL May 30 '18 at 17:18
• Try an odd number of trapezoids (evenly spaced) and you don't get error zero anymore. For example $n=3$ the trapazoid rule overestimates by $1/9$ – N8tron May 30 '18 at 17:28
• Related: For numerical integration, is it true that higher degree of precision gives better accuracy always? (the answer is no) – Winther May 30 '18 at 17:34

In your example this happens because: 1) the function is not a polynomial so one should not expect quadrature rules to give the exact result 2) it's a perfect function for the trapezoidal rule because it consists of two trapezoids so this rule will give exact results if and only if $x=0$ is a grid-point.