Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Physics LibreTexts

1.15: Gaussian Quadrature - the Algorithm

( \newcommand{\kernel}{\mathrm{null}\,}\)

Gaussian quadrature is an alternative method of numerical integration which is often much faster and more spectacular than Simpson’s rule. Gaussian quadrature allows you to carry out the integration

11f(x)dx.

But what happens if your limits of integration are not ±1? What if you want to integrate

baF(t)dt?

That is no problem at all – you just make a change of variable. Thus, let

x=2tabba,t=12[(ba)x+a+b],

and the new limits are then x=±1.

At the risk of being pedagogically unsound I’ll describe first, without any theoretical development, just what you do, with an example – as long as you promise to look at the derivation afterwards, in Section 1.16.

For our example, let’s try to evaluate

I=π/20sinθdθ.

Let us make the change of variable given by Equation 1.15.3 (with t=θ, a=0, b=π/2), and we now have to evaluate

I=11π4sinπ4(x+1)dx.

For a 5-point Gaussian quadrature, you evaluate the integrand at five values of x, where these five values of x are the solutions of P5(x)=0 given in Section 1.14, P5 being the Legendre polynomial. That is, we evaluate the integrand at x=±0.906 469 514 203, ±0.538 469 310 106 and 0.

I now assert, without derivation (until later), that

I=5i=1c5,i f(x5,i),

where the coefficients cl,i (all positive) are listed with the roots of the Legendre polynomials in Section 1.14.

Let’s try it.

x5,if(x5,i)c5,i+0.906 179 845 9390.783 266 908 390.236 926 885 06+0.538 469 310 1060.734 361 739 690.478 628 670 500.000 000 000 0000.555 360 367 270.568 888 888 890.538 469 310 0060.278 501 544 600.478 628 670 500.906 179 845 9390.057 820 630 350.236 926 885 06

and the expression 1.15.6 comes to 1.000 000 000 04, and might presumably have come even closer to 1 had we given xl,i, and cl,i, to more significant figures.

You should now write a computer program for Gaussian quadrature – you will have to store the xl,i and cl,i of course. You have presumably already written a program for Simpson’s rule.

In a text on integration, the author invited the reader to evaluate the following integrals by Gaussian quadrature:

(a)1.51x2lnxdx(e)π/40e3xsin2xdx(b)10x2xxdx(f)1.612xx24dx(c)0.3502x24dx(g)3.53xx24dx(d)π/40x2sinxdx(h)π/40cos2xdx

All of these can be integrated analytically, so I am going to invite the reader to evaluate them first analytically, and then numerically by Simpson’s rule and again by Gaussian quadrature, and to see at how many points the integrand has to be evaluated by each method to achieve nine or ten figure precision. I tried, and the results are as follows. The first column is the answer, the second column is the number of points required by Simpson’s rule, and the third column is the number of points required by Gaussian quadrature.

(a)0.192 259 358334(b)0.160 602 794995(c)0.176 820 020194(d)0.088 755 284 41115(e)2.588 628 6334537(f)0.733 969 1751438(g)0.636 213 346315(h)0.642 699 082595

Let us now have a look at four of the integrals that we met in Section 1.2.

1. 10x4dx2(1+x2). This was straightforward. It has an analytic solution of 18ln(1+2)216=0.108 709 465. I needed to evaluate the integral at 89 points in order to get this answer to nine significant figures using Simpson’s rule. To use Gaussian quadrature, we note that integrand contains only even powers of x and so it is symmetric about x=0, and therefore the integral is equal to 1211x4dx2(1+x2), which makes it immediately convenient for Gaussian quadrature! I give below the answers I obtained for 3- to 7-point Gaussian quadrature.

30.108 667 03640.108 711 21550.108 709 44160.108 709 46370.108 709 465Correct answer0.108 709 465

2. 20y2dy2y. This had the difficulty that the integrand is infinite at the upper limit. We got round this by means of the substitution y=2sin2θ, and the integral becomes 128π/20sin5θdθ. This has an analytic solution of 8192/15=.6033977866. I needed 59 points to get this answer to ten significant figures using Simpson’s rule. To use Gaussian quadrature we can let y=1+x, so that the integral becomes , 11(1+x)2dy1x, which seems to be immediately suitable for Gaussian quadrature. Before we proceed, we recall that the integrand becomes infinite at the upper limit, and it still does so after our change of variable. We note, however, that with Gaussian quadrature, we do not evaluate the integrand at the upper limit, so that this would appear to be a great advantage of the method over Simpson’s method. Alas! – this turns out not to be the case. If, for example, we use a 17-point quadrature, the largest value of x for which we evaluate the integrand is equal to the largest solution of P17(x)=0, which is 0.9906. We just cannot ignore the fact that the integrand shoots up to infinity beyond this, so we have left behind a large part of the integral. Indeed, with a 17-point Gaussian quadrature, I obtained an answer of 5.75, which is a long way from the correct answer of 6.03.

Therefore we have to make a change of variable, as we did for Simpson’s method, so that the upper limit is finite. We chose y=2sin2θ which changed the integral to 128π/20sin5θdθ. To make this suitable for Gaussian quadrature, we must now make the further substitution (see Equation 1.15.3) x=4θ/π1, θ=π4(x+1). If we wish to impress, we can make the two substitutions in one step, thus: Let y=2sin2π4(1+x), x=4πsin1y21. The integral becomes 8π11sin5π4(1+x)dx, and there are no further difficulties. With a 9-point integration, I obtained the answer, correct to ten significant figures, 6.033 977 866. Simpson’s rule required 59 points.

3. π/20secθdθ. This integral occurs in the theory of a simple pendulum swinging through 90. As far as I can tell it has no simple analytical solution unless we have recourse to unfamiliar elliptic integrals, which we would have to evaluate numerically in any case. The integral has the difficulty that the integrand is infinite at the upper limit. We get round this by means of a substitution. Thus let sinϕ=2sin12θ. (Did you not think of this?) The integral becomes 2π/20dϕ112sin2ϕ. I needed 13 points by Simpson’s rule to get the answer to ten significant figures, 2.622 057 554. In order to make the limits ±1, suitable for Gaussian quadrature, we can make the second substitution (as in example 2), ϕ=π4(x+1). If we wish truly to impress our friends, we can make the two substitutions in one step, thus: Let sinπ4(1+x)=2sin12θ. (No one will ever guess how we thought of that!) The integral becomes π211dx2sin2π4(x+1), which is now ready for Gaussian quadrature. I obtained the answer 2.622 057 554 in a 10-point Gaussian quadrature, which is only a little faster than the 13 points required by Simpson’s rule.

4. 0dyy5(e1/y1). This integral occurs in the theory of blackbody radiation. It has the difficulty of an infinite upper limit. We get round this by means of a substitution. Thus let y=tanθ. The integral becomes π/20c3(c2+1)ec1dθ, where c=cotθ. It has an analytic solution of π4/15=6.493 939 402. I needed 261 points by Simpson’s rule to get the answer to ten significant figures. To prepare it for Gaussian quadrature, we can let θ=π4(x+1), as we did in example 2, so that the integral becomes ,where π411c3(c2+1)ec1dx, where c=cotπ4(x+1). Using 16- point Gaussian quadrature, I got 6.48. Thus we would need to extend our table of constants for the Gaussian method to much higher order in order to use the method successfully. Doubtless the Gaussian method would then be faster than the Simpson method – but we do not need an extensive (and difficult-to-calculate) set of constants for the latter. A further small point: You may have noticed that it is not immediately obvious that the integrand is zero at the end points, and that some work is needed to prove it. But with the Gaussian method you don’t evaluate the integrand at the end points, so that is one less thing to worry about!

Thus we have found that in most cases the Gaussian method is far faster than the Simpson method. In some cases it is only marginally faster. In yet others it probably would be faster than Simpson’s rule, but higher-order constants are needed to apply it. Whether we use Simpson’s rule or Gaussian quadrature, we have to carry out the integration with successively higher orders until going to higher orders results in no further change to the number of significant figures desired.


This page titled 1.15: Gaussian Quadrature - the Algorithm is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Jeremy Tatum via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?