The Mathematica function NIntegrate uses as one of its methods a fairly sophisticated Gauss-Kronrod-based algorithm. The package NumericalMath`GaussianQuadrature` allows you to easily study some of the theory behind ordinary Gaussian quadrature which is a little less sophisticated.
The basic idea behind Gaussian quadrature is to approximate the value if an integral as a linear combination of values of the integrand evaluated at specific points:
Since there are free parameters to be chosen (both the abscissas and the weights ) and since both integration and the sum are linear operations, we can expect to be able to make the formula correct for all polynomials of degree less than about
. In addition to knowing what the optimal abscissas and weights are, it is often desirable to know how large the error in the approximation will be. This package allows you to answer both of these questions.
This loads the package.
Finding formulas for Gaussian quadrature.
This gives the abscissas and weights for the five-point Gaussian quadrature formula on the interval (
In:= GaussianQuadratureWeights[5, -3, 7]
Here is the error in that formula. Unfortunately it involves the tenth derivative of
at an unknown point so we don't really know what the error itself is.
In:= GaussianQuadratureError[5, f, -3, 7]
We can see that the error decreases rapidly with the length of the interval.
In:= GaussianQuadratureError[5, f, a, a+h]