You are on page 1of 12

Numeri

al Integration
Computational Te hniques II

Contents

1 Introdu tion 1

2 Newton-Cotes quadrature 2
2.1 Trapezium rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Simpson's rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 A simpler way to derive Newton-Cotes formulae . . . . . . . . . . 3
2.4 Error analysis for Newton-Cotes formulae . . . . . . . . . . . . . 3

3 Spe ial ase of even n 4


3.1 Composite Newton-Cotes quadrature . . . . . . . . . . . . . . . . 5

4 Gaussian quadrature 7
4.1 Orthogonal polynomials . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 More general Gaussian quadrature . . . . . . . . . . . . . . . . . 10
4.3 Standard weights . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1 Introdu tion

Suppose that we are given a fun tion f (x); and we are to ompute
Z b

f (x) dx;
a

where a; b are given numbers. One method is to rst nd an inde nite integral
of f (x) : Z
F (x) = f (x) dx;
and then to ompute F (b) F (a): This method is alled the analyti al method,
and depends on our ability to ompute the inde nite integral F (x): There are
many situations where omputing F (x) is di ult or even impossible. In su h
ases, we resort to numeri al integration or quadrature. A numeri al integration
method has the advantage that we do not need to nd the inde nite integral, but
it has the disadvantage that the answer may be approximate. There are many
di erent methods of numeri al integration. In this ourse, we shall learn about
two types of quadrature algorithms: Newton-Cotes quadrature and Gaussian
quadrature.

1
2 Newton-Cotes quadrature

Here we shall assume that we are given the value of f (x) at regularly spa ed
points, a = x0 ; :::; xn = b; where xi = a + ih; for i = 0; :::; n and h = (b a)=n:
Then we an interpolate the n + 1 points
(x0 ; y0 ); :::; (xn ; yn )
using a (unique) polynomial p(x) of degree  n and use
Z b

p(x)dx
a

as an approximation for Z b

f (x)dx:
a

This is alled Newton-Cotes quadrature. Of spe ial interest are the simplest two
ases: n = 1 and n = 2: These are alled, respe tively, the trapezium rule and
Simpson's rule.

2.1 Trapezium rule

This is Newton-Cotes quadrature with n = 1: So we shall assume that we know


that f (x) is known only at x0 = a and xn = x1 = b: The interpolating polyno-
mial is of degree 1, i.e., a straight line. The area below the the interpolating
polynomial is thus the shaded trapezium shown below.

f(b)

f(a)

a=x0 b=x1

h
Trapezium rule

Its area is
h
(f (x0 ) + f (x1 )):
2
Noti e that this is just a linear ombination of the f (xi )'s. It turns out that
this is a general behaviour for Newton-Cotes formulae.

2.2 Simpson's rule

This is Newton-Cotes quadrature with n = 2: Here f (x) is assumed to be known


for 3 regularly spa ed points: x0 = a; x1 = a+h; and x2 = b; where h = (b a)=2:
We shall t a polynomial of degree  n = 2 through the three points.
The omputation is now more ompli ated than the trapezium rule. However,
the nal answer turns out to be quite neat:
h
(f (x0 ) + 4f (x1 ) + f (x2 )):
3

2
2.3 A simpler way to derive Newton-Cotes formulae

We have already mentioned that the Newton-Cotes formula for any n is a linear
ombination of f (xi )0 s; i.e., of the form
0 f (x0 ) +    + f (x );
n n

where the numbers 0 ; :::; n may depend on a; b; n but not on f:

Exer ise 1 Show that this is true by observing that f [x0 ; :::; xk 's are linear ombinations of

f (xi )'s. 

On e we know that i 's are free of f; we an take spe ial simple hoi es of f
to ompute them. For instan e, to derive trapezium rule (whi h uses linear
interpolation) we shall take f (x) = 1 and f (x) = x: The rst hoi e will give:
b a = 0 + 1 ;
while the se ond hoi e gives
(b2 a2 )=2 = 0 a + 1 b
Solving these two equations we get
h
0 = 1 = ;
2
whi h gives the trapezium rule.
Similarly, we an take f (x) = 1; x and x2 for Simpson's rule to get 3 equations:
0 + 1 + 2 = b a
x0 0 + x1 1 + x2 2 = (b2 a2 )=2
x20 0 + x21 1 + x22 2 = (b3 a3 )=3
Noti e that this system an be written as
2 32 3 2 3
1 1 1 0 (b a)
4 x0 x1 x2 5 4 1 5 = 4 (b2 a2 )=2 5 :
x20 x21 x22 2 (b3 a3 )=3
The oe ient matrix is a Vandermonde matrix, and hen e is nonsingular. It
should not be di ult to he k that the unique solution is given by
0 = h=3; 1 = 4h=3; 2 = h=3:

2.4 Error analysis for Newton-Cotes formulae

By onstru tion the Newton-Cotes formula of degree n is exa t (i.e., involves


no error) if f (x) is a polynomial of degree  n: In parti ular, the trapezium
rule is exa t if f (x) is linear. However, it may not be exa t for higher degree
polynomials.

Example Let us apply the trapezium rule to f (x) = x2 for x0 = 0 and x1 = 1: The a tual
integral is Z1
1
x2 dx = :
0 3

3
Using trapezium rule we get
1 1 1
(0 + 1) = 6= :
2 2 3


However, something di erent happens for Simpson's rule. Sin e it is the Newton-
Cotes formula for n = 2; it is exa t for polynomials of degree  2: However, it
turns out that it is also exa t for polynomials of degree 3.

Example Let us apply Simpson's rule to f (x) = x3 for general a; b: The a tual answer is
Z b
(b4 a4 )
x3 dx = :
a 4
To apply Simpson's rule we noti e that x0 = a; x1 = (a + b)=2; x2 = b and
h = (b a)=2: So Simpson's rule gives
h
(x30 + 4x31 + x32 );
3
whi h is same as the exa t integral ( he k!) 

3 Spe ial ase of even n


The reason behind the exa tness of Simpson's rule for ubi polynomials is
shown in the diagram below.

quadratic interpolant

+ f(x) is cubic
-

Why Simpson's rule works for ubi polynomials

The two areas marked + and are equal, and hen e an el ea h other out.
This is a tually a general phenomenon for Newton-Cotes formulae for even n:
They are exa t if f (x) is a polynomial of degree  n + 1: However, if n is odd
then it is guaranteed to be exa t only if f (x) is a polynomial of degree  n: To
prove this let f (x) be a polynomial of degree n + 1: Then it oin ides with the
(n+1)-th degree interpolating polynomial, and hen e
f (x) = f [x0 + (x x0 )f [x0 ; x1 +    + f [x0 ; :::x (x x0 )    (x x ):
n n

If we use n-point Newton-Cotes formula, then we integrate only the rst n terms.
So we miss the last term, whose integral is
Z x n
f [x0 ; :::x
n (x x0 )    (x x )dx: n
x0

4
Sin e the xi 's are regularly spa ed, the polynomial
(x x0 )    (x x )
n

has a graph like the following. Ea h shaded \hump" has the same area. For even
n there are exa tly n=2 humps above and below the x-axis. So the algebrai
sum of the areas is zero.

n=3 n=2

x x x2 x3 x x1 x
0 1 0 2

The shaded areas an el out for even n

Hen e the result.

3.1 Composite Newton-Cotes quadrature

As one an see easily, the Newton-Cotes formulae be ome more and more om-
pli ated as n in reases. To avoid this, we use pie ewise polynomial interpolation.
Ea h pie e is of a low degree, and we apply the low degree Newton-Cotes for-
mula for ea h pie e separately, and then add the results. The following diagram
shows how we an approximate f (x) by pie ewise linear interpolation.

f(x) Small line segments


Curve

yi1 y
i

a b a h b

Pie ewise linear interpolation

Over ea h pie e we apply trapezium rule to get omposite trapezium rule:

Choose some positive integer n: Split the interval [a; b into n equal parts:
a; a + h; a + 2h; :::; a + nh = b;
where h = (b a)=n: Compute f (x) at ea h of these points:
y = f (a + ih) for i = 0; 1; :::; n:
i

Now ompute
Z b
h
f (x) dx  [y0 + 2(y1 +    + y 1 ) + yn :
a 2 n

5
Example Compute Z
p1 e
2
2
x =2
dx;
2 1

by trapezium rule using n = 5: We split the interval [1; 2 into 4 equal parts and
ompute yi 's.

i yi

0 0.2420
1 0.1826
2 0.1295
3 0.0863
4 0.0540

So by applying trapezium rule the integral is approximately


0:25
2
 [0:2420 + 2  (0:1826 + 0:1295 + 0:0863) + 0:0540 = 0:1366:
It is instru tive to ompare this with the a tual value, whi h is 0.1359. 

Similarly, we an have omposite Simpson's rule by interpolating f (x) by pie e-


wise quadrati polynomials. Noti e that ea h quadrati polynomial (i.e., parabola)
needs 3 points to x it. So we t one parabola over [x0 ; x2 ; the next parabola
over [x2 ; x4 ; and so on.

As in omposite trapezium rule we need to subdivide the interval [a; b into n


equal parts. But for Simpson's rule n needs to be an even number, say 2k:
Evaluate f (x) at the subdivision points to get
y0 ; y1; :::; y2 : k

But now use the following formula


Z
 h3 [(y
b

f (x) dx 0 + y2k )
a

+2(y2 + y4 +    + y2(k 1) )
+ 4(y1 + y3 +    + y2k 1 ) :

Example Now let us ompute the integral from the last example using Simpson's rule.
We shall again use n = 4: This time the value is
0:25
3
[  (0:2420 + 0:0540)
+ 2  (0:1295) + 4  (0:1826 + 0:0863) = 0:1359;

whi h is orre t up to 4 de imal pla es. Noti e how Simpson's rule gives here
more a urate value than the trapezium rule, though we have used the same n
in both methods. 

6
4 Gaussian quadrature

So far we have been using f (x) only via its values at some regularly spa ed
points xi 's. In some ases, it may be impossible to know f (x) at other points,
e.g., if f (x) is not known analyti ally but only measured by some experiment.
However, in many other ases, it may be possible to ompute f (x) at any value
of x of our hoi e. Then one may like to hoose the values xi 's arefully to
improve the a ura y of the quadrature in stead of using regularly spa ed xi 's.
This is the main idea behind Gaussian quadrature. Here we try to approximate
the integral as Z b

f (x)dx  0 f (x0 ) +    + f (x ); n n
a

where both i 's and xi 's are to be hosen to in rease the a ura y of the ap-
proximation. Sin e we are hoosing 2(n + 1) numbers here, (as ompared to
only (n + 1) in Newton-Cotes) we would expe t that Gaussian quadrature is
more a urate (i.e., exa t for higher degree polynomials) than Newton-Cotes
quadrature with the same n:
Theorem
Let x0 ; :::; xn be n + 1 distin t numbers. Let m  1 be any integer. Then the
following two statements are equivalent.
1. There are oe ients 0 ; :::; n su h that for any polynomial f (x) of degree
 n + m; Z b X n

f (x)dx = f (x ):
i i (gau)
a
i=0

2. The polynomial
p(x) = (x x0 )(x x1 )    (x x ) n

satis es Z b

x p(x)dx = 0
k
8k = 0; 1; :::; m 1: (orth)
a

Proof:

(1 ) 2): Let 0 ; :::; n satisfy (gau) for all polynomials of degree  n + m: In


parti ular, for all k  m 1; the polynomial xk p(x) is of degree  n + m; sin e
degree of p(x) is n+1: Putting f (x) = xk p(x) in (gau) we get, for k = 0; :::; m 1;
Z b X
n

x p(x)dx =
k
x p(x ) = 0;
i
k
i i
a
i=0

sin e p(xi ) = 0 for all i: So (orth) holds.


(2 ) 1): We are given x0 ; :::; xn su h that (orth) holds. We are to get 0 ; :::; n
su h that (gau) holds for degrees  n + m: In parti ular, it must hold for degrees
0; 1; :::; n: So as in the Newton-Cotes approa h we get a Vandermonde system
by onsidering f (x) = xk for k = 0; 1; :::; n:
2
1  1 32 3 2 3
1 0 0
66 x x  x 7
0 766 7
7 6
61 7
7 n 1 1
66 x x  x 7
2
0 7 6
6 7
7 =6 7
62
1 7;
2
2 2
64 . 76 . 7 6 . 7
n
.
.. . .. .. 5 4 .. 5 4 .. 5
x0 x1
n n
 x n
n
n n

7
where Z b

=
k x dx = (b
k k+1
ak+1
)=(k + 1):
a

The xi 's being distin t, the oe ient matrix is nonsingular, and hen e this
system uniquely xes the i 's. Thus, by onstru tion, (gau) holds for degrees
 n: We need to show that it also hold for degrees n + 1; :::; n + m: Enough
to show that (gau) holds for f (x) = xk where k = n + 1; :::; n + m: We shall
pro eed by indu tion. First onsider f (x) = xn+1 : For this it is enough to show
that (gau) holds for f (x) = p(x); sin e p(x) is an (n + 1)-degree polynomial
and the (gau) already holds for 1; x; x2 ; :::; xn : Thus, we are to show that
Z b X n

p(x)dx = p(x );
i i
a
i=0

whi h is trivial, sin e the l.h.s. vanishes by (orth) and the r.h.s. vanishes
by de nition of p(x): This ompletes the proof for f (x) = xn+1 : Now assume
that (gau) holds for f (x) = xn+1 ; :::; xn+k : We shall show that (gau) holds for
f (x) = xn+k+1 : But this is the same as showing that (gau) holds for xk p(x);
sin e it is an n + k + 1-degree polynomial and (gau) already holds for powers
 n + k: So we are to show
Z b X n

x p(x)dx =
k
x p(x );
i
k
i
a
i=0

whi h is again trivial, sin e the l.h.s. vanishes by (orth) and the r.h.s. vanishes
by de nition of p(x): 

4.1 Orthogonal polynomials

The above theorem provides a useful approa h to Gaussian quadrature. Con-


sider the set of all polynomials f (x) de ned on [a; b: Clearly, it is a ve tor spa e
over R under usual addition and s alar multipli ation. De ne the inner produ t
Z b

hf; gi = f (x)g(x)dx:
a

Then (orth) says that p(x) is orthogonal to all polynomials of degree  m 1:


In other words, if q (x) is any polynomial with degree  m 1; then
hp; qi = 0:
Now, we an apply Gram-S hmidt orthogonalization to the basis
f1; x; x ; x ; :::g
2 3

w.r.t. the above inner produ t to get an orthogonal basis:


fp (x); p (x); p (x); :::g
0 1 2

It is easy to see that ea h pk (x) has degree k: The following theorem is an


important property of these orthogonal polynomials.
Theorem
Ea h pk (x) has k distin t, real zeros inside the open interval (a; b):

8
Proof:

We shall not prove this in this ourse. 

Let zk;0 ; :::; zk;k 1 be the zeros of pk (x): Then Gaussian quadrature with n + 1
points uses the following approximation:
Z b X
n

f (x)dx  n+1;i f (z n+1;i );


a
i=0

where the n+1;i 's are obtained from the Vandermonde system with xi = zn+1;i :
This is exa t if f (x) is a polynomial of degree  2n:

Example Let us expli itly ompute p0 (x); p1 (x) and p2 (x): Noti e that we are only about
the roots of the polynomials, so we shall save ourselves the trouble of normalizing
the polynomials. We start with the usual basis
u0 (x) = 1; u1 (x) = x; u2(x) = x2 ; : : : :
We take
p0 (x) = u0 (x) = 1:
Taking out the p0 - omponent from u1 we are left with

p1 = u1
hu ; p i p
1 0
= u1 = x;
hp ; p i
0 0
0

sin e Z 1
hu ; p i =
1 0 xdx = 0:
1

To nd p2 we similarly take out the p0 and p1 - omponents from u2 to get

p2 = u2
hu ; p i p
2 0 hu ; p i p :
2 1
hp ; p i
0 0
0
hp ; p i
1 1
1

After some omputation this turns out to be


1
p2 (x) = x2 :
3


Exer ise 2 Che k that p3 (x) = x


3
3x=5 and p4 (x) = x
4 2
6x =7 + 3=35: 

Example People have omputed the zeros of pk (x)'s and the orresponding i 's and pub-
lished the values as tables. Here are the values for k = 5:

i z5 ;i 5 ;i

0 0:00000000 0:56888889
1 0:53846931 0:47862867
2 0:53846931 0:47862867
3 0:90617985 0:23692689
4 0:90617985 0:23692689

9
Thus, if we want to integrate f (x) = 1=(x + 3); we shall ompute as follows.

i f (z5;i ) 5;i f (z5;i )


0 0:33333333 0:18962962
1 0:28260808 0:13526433
2 0:40625128 0:19444351
3 0:25600460 0:06065437
4 0:47759593 0:11315529
Total - 0.69314712
Thus, we estimate Z 1
dx
x+3
 0:69314712:
1

4.2 More general Gaussian quadrature

In fa t, Gaussian quadrature is even more ambitious. It tries to hoose i 's and


xi 's in a way that the formula is exa t for fun tions of the form
f (x) = w(x)p(x);
where w(x) is some given positive fun tion ( alled the weight fun tion) and
p(x) is a polynomial of some suitable degree. The optimal hoi e of i 's and
xi 's will depend on the parti ular weight fun tion used. Depending on the
hoi e of the weight fun tion we have di erent forms of Gaussian quadrature,
e.g., Gauss-Legendre, Gauss-Laguerre et . So far we have been working with
the weight fun tion w(x)  1: If we further hoose (without loss of generality)
a = 1 and b = 1 then the resulting orthogonal polynomials are alled Legen-
dre polynomials, and the orresponding Gaussian quadrature formula is alled
Gauss-Legendre formula.
We an hoose w(x); a and b to suit parti ular needs. The hoi e an be quite
general (in luding a = 1 and/or b = 1:) The only restri tions are:
1. w(x) > 0 8x 2 (a; b) (In fa t, we an allow w(x) to be zero at nitely
many points.)
2. The integral Z b

:=
k w(x)x dxk

must be nite for all k:

These two onditions guarantee that we an de ne the inner produ t


Z b

hf; gi = w(x)f (x)g(x)dx:


a

As before we an apply Gram-S hmidt orthogonalization to the basis


f1; x; x ; x ; :::g
2 3

w.r.t. the above inner produ t to get an orthogonal basis:


fp (x); p (x); p (x); :::g
0 1 2

10
It is easy to see that ea h pk (x) has degree k: The following theorem is a gen-
eralization of the last theorem.
Theorem
Ea h pk (x) has k distin t, real zeros inside the open interval (a; b):
Proof:

We shall not prove this in this ourse. 

On e we hoose w(x); a and b; we have the orresponding Gaussian quadrature


formula: Z b n
X
w(x)f (x)dx  n+1;i f (z n+1;i );
a
i=0

where zn+1;0 ; :::; zn+1;n are the zeros of pn+1 (x) and the n+1;i 's are obtained
from 2 32 3 2 3
1 1  1 n+1;0 0
66 x0 x1    x 77 66
n n+1;1
7
7 6
6 1 7
7
66 x20 x21    x 77 66
2
n+1;2
7
7 6
= 6 2 7
7;
64 .. 7 6 7
n
.. .. ..
. . . 54 . 5 4  5
x0 x1n n
 x n
n
n+1;n
n

where Z b

= k x w(x)dx:
k

This formula is exa t if f (x) is a polynomial of degree  2n:

4.3 Standard weights

Certain hoi es of weights are more popular than others. Here is an in omplete
list.

Name w(x) (a; b)


Gauss-Legendre 1 ( 1; 1)
Gauss-Laguerre e x
(0; 1)
Gauss-Hermite e
p
x
2
( 1; 1)
Gauss-Chebyshev 1= 1 x 2 ( 1; 1)

Standard tables are available for zk;i 's and n;i 's for these ases. Here are some
of these.

Gauss-Laguerre
i z5 ;i 5 ;i

0 0:263560319718 0:521755610583
1 1:413403059107 0:398666811083
2 3:596425771041 0:759424496817e 1
3 7:085810005859 0:361175867992e 2
4 12:640800844276 0:233699723858e 4

For Gauss-Chebyshev there are simple losed-form formulae for zk;i 's and k;i 's:
(2i + 1) 
z = os ; = :
k;i
2k k;i
k
Here is the table for Gauss-Hermite.

11
Gauss-Hermite
i z5 ;i 5 ;i

0; 1 2:0201828705 0:0199532421
2; 3 0:9585724646 0:3936193232
4 0:0000000000 0:9453087205

12

You might also like