Вы находитесь на странице: 1из 10

W EEK

6
Numerical Integration

Study Organiser

Before you begin this note, please check through your study organiser given below. It shows
the topics that we’ll be covering, the skills you need to acquire (the learning outcomes) and
the resources and activities you are given to help you acquire these skills.

Topics Learning Outcomes Learning Learning


Resources Activities
Integration via Use Lagrange interpolating polynomial to Readings - Section 6.1 Tutorial 6
Polynomial derive an approximation for a definite integral Examples 6.1-6.5 Quiz 6
Interpolation and use it to approximate definite integrals. Glossary 6
Method of Use the method of undetermined coefficient Readings - Section 6.2 Homework 6
Undetermined to derive an approximation for a definite Examples 6.6-6.9 Test 1
Coefficients integral.

Introduction

Numerical integration is the process of producing a numerical value for the integration of a
function over a set.

Consider the definite integral


Z b
f (x) dx.
a
One can evaluate a definite integral by applying the Fundamental Theorem of Calculus
Z b
f (x) dx = F (b) − F (a)
a
2 W EEK 6

where F (x) is an antiderivative of f (x). Note that the fundamental theorem of calculus
requires that the antiderivative of f (x) must exist. However, if the integrand f (x) does not
have an antiderivative, then we can not apply this theorem. Example the integral
Z 1
2
ex dx
0

2
is not solvable by the fundamental theorem of calculus since ex does not have an antideriva-
tive.

Z b
One powerful method for numerically computing the integral f (x )dx (where f (x) may
a
be a function that does not have any antiderivative) is to replace f by another function g that
approximates f well and is easily integrated:
Z b Z b
f (x) dx ≈ g(x) dx
a a

Polynomials are good candidates for g, and indeed g can be a polynomial that interpolates f
at certain set of nodes.

6.1 Integration via Polynomial Interpolation

We select the nodes x0 , x1 , . . . , xn and set up the Lagrange interpolation process. Recall the
Lagrange cardinal functions
n
Y x − xj
li (x) = (0 ≤ i ≤ n)
j=0
xi − xj
j6=i

And the Lagrange polynomials of degree at most n is


n
X
p(x) = f (xi )li (x)
i=0

Then
Z b Z b n
X Z b
f (x)dx ≈ p(x)dx = f (xi ) li (x)dx
a a i=0 a

Hence
Z b n
X
f (x)dx ≈ Ai f (xi ) (6.1)
a i=0
W EEK 6 3

where
Z b
Ai = li (x)dx
a

Formula (6.1) is called a Newton-Cotes formula if the nodes are equally spaced.

Example 6.1. Derive the Newton-cotes formula for


Z 1
f (x)dx
0
1
based on the Lagrange interpolation polynomial at the nodes 0, 2 and 1.
Z 1
2
Apply this result to approximate the integral ex dx.
0

Solution
We want to derive a formula of the form
Z 1
f (x)dx ≈ A0 f (0) + A1 f ( 12 ) + A2 f (1)
0
1
Here x0 = 0, x1 = 2 and x2 = 1, so the Lagrange cardinal functions are

(x − 21 )(x − 1)
l0 (x) = = 2x2 − 3x + 1
(0 − 12 )(0 − 1)
(x − 0)(x − 1)
l1 (x) = 1 1 = −4x2 + 4x
( 2 − 0)( 2 − 1)
(x − 0)(x − 12 )
l2 (x) = = 2x2 − x
(1 − 0)(1 − 12 )
It follows that
1 1
1
Z Z
A0 = l0 (x)dx = (2x2 − 3x + 1)dx =
0 0 6
1 1
2
Z Z
A1 = l1 (x)dx = (−4x2 + 4x)dx =
0 0 3
1 1
1
Z Z
A2 = l2 (x)dx = (2x2 − x)dx =
0 0 6
Hence
1
1 2 1
Z
f (x)dx ≈ f (0) + f ( 12 ) + f (1).
0 6 3 6
So
1
1 2 1
Z
2
ex dx ≈ e0 + e1/4 + e1 ≈ 1.47573.
0 6 3 6
4 W EEK 6

Example 6.2. Use the Lagrange interpolation polynomial to derive the formula of the form

1    
1 2
Z
f (x)dx ≈ Af + Bf
0 3 3
Z 1
Apply this result to approximate the integral cos(ex )dx.
0

Solution
1
Here x0 = 3 and x1 = 32 , so the Lagrange cardinal functions are

2 1
x− 3 x− 3
l0 (x) = 1 2 = −3x + 2 and l1 (x) = 2 1 = 3x − 1
3 − 3 3 − 3

It follows that

1 1
1
Z Z
A = l0 (x)dx = (−3x + 2)dx =
0 0 2
1 1
1
Z Z
B = l1 (x)dx = (3x − 1)dx =
0 0 2

Hence

1    
1 1 1 2
Z
f (x)dx ≈ f + f .
0 2 3 2 3

So
1
1 1
Z
cos(ex )dx ≈ cos(e1/3 ) + cos(e2/3 ) ≈ −0.096893.
0 2 2

Example 6.3. Show that if n = 1 in the Newton-Cotes formula, then

b
b−a
Z
f (x)dx ≈ [f (a) + f (b)]
a 2

Solution
If n = 1 then the nodes are x0 = a and x1 = b. So the Lagrange cardinal functions are

x−b x−a
l0 (x) = and l1 (x) =
a−b b−a
W EEK 6 5

Now
b b
x−b
Z Z
A0 = l0 (x)dx = dx
a a a−b
b  2 b
1 1 x
Z
= (x − b) dx = − bx
a−b a a−b 2 a
 
1 1 2 1 2
= − b − a + ab
a−b 2 2
−1
b2 + a2 − 2ab
 
=
2(a − b)
−1
= (a − b)2
2(a − b)
1
= (b − a)
2

Similarly

b b
x−a 1
Z Z
A1 = l1 (x)dx = dx = (b − a)
a a b−a 2

Hence, the corresponding Newton-Cotes formula is

b
b−a
Z
f (x)dx ≈ [f (a) + f (b)]
a 2

This is known as Trapezoid Rule.

Example 6.4. Consider the xi values (for i = 0, 1, 2) given in the following table.

i 0 1 2
xi -1 0 1

1. Find the Lagrange cardinal functions l0 (x), l1 (x) and l2 (x).

2
P
2. Verify that li (x) = 1.
i=0

3. Use the cardinal functions in part (a) to derive the Newton-Cotes formula
Z 1
f (x)dx ≈ A0 f (x0 ) + A1 f (x1 ) + A2 f (x2 ).
−1

Solution
6 W EEK 6

1. The cardinal functions are:


x(x − 1) 1
l0 (x) = = (x2 − x)
(−1)(−1 − 1) 2
(x + 1)(x − 1)
l1 (x) = = 1 − x2
(0 + 1)(0 − 1)
(x + 1)x 1
l2 (x) = = (x2 + x)
(1 + 1)(1) 2

2    
X 1 1 2 1 1
2. li (x) = −1+ x + − + x + 1 = 0x2 + 0x + 1 = 1
2 2 2 2
i=0

3.
1
1 1 2 1
Z Z
A0 = l0 (x)dx = (x − x)dx =
−1 2 −1 3
Z 1 Z 1
4
A1 = l1 (x)dx = (1 − x2 )dx =
−1 −1 3
Z 1 Z 1
1 1
A2 = l2 (x)dx = (x2 + x)dx =
−1 2 −1 3
1
1 4 1
Z
Thus f (x)dx ≈ f (−1) + f (0) + f (1).
−1 3 3 3

Example 6.5. More Examples

1. Consider a numerical integration of the form


Z 1 r ! r !
3 3
f (x)dx ≈ Af − + Bf (0) + Cf
−1 5 5

What three integrals that must be evaluated to determine A, B and C in a Newton’s


cotes formula? Solve for A, B and C.
q q
Solution Here the nodes are x0 = − 35 , x1 = 0 and x2 = 35 , so the Lagrange cardinal
functions are
 q 
(x − 0) x − 35
r !
5 2 3
ℓ0 (x) =  q  q q = x − x
− 3 −0 − 3 − 3 6 5
5 5 5
 q  q 
x + 35 x − 35 5

3

5
2
ℓ1 (x) = q  q  =− x − = − x2 + 1
3 5 3

0 + 35 0 − 35
 q 
x + 35 (x − 0)
r !
5 2 3
ℓ2 (x) = q q  q = x + x
3
+ 3 3
− 0 6 5
5 5 5
W EEK 6 7

It follows that
r !
1 1
5 3 5
Z Z
A = ℓ0 (x)dx = x2 − x =
−1 −1 6 5 9
1 1
5 8
Z Z
B = − x2 + 1 =
ℓ1 (x)dx =
−1 −1 3 9
Z 1 Z 1 r !
5 3 5
C = ℓ2 (x)dx = x2 + x =
−1 −1 6 5 9

2. Derive the Newton-cotes formula for


Z 1
f (x)dx
0

based on the Lagrange interpolation polynomial at the nodes -2,-1, and 0. Apply this
result to evaluate the integral when f (x) = sin πx.

Solution
We want to derive a formula of the form
Z 1
f (x)dx = Af (−2) + Bf (−1) + Cf (0)
0

Here x0 = −2, x1 = −1 and x2 = 0, so the Lagrange cardinal functions are


(x + 1)(x − 0) 1 2 
ℓ0 (x) = = x +x
(−2 − 1)(−2 − 0) 2
(x + 2)(x − 0)
= − x2 + 2x

ℓ1 (x) =
(−1 + 2)(−1 − 0)
(x + 2)(x + 1) 1 2 
ℓ2 (x) = = x + 3x + 2
(0 + 2)(0 + 1) 2
It follows that
1 1 1
1 x3 x2

1 2 5
Z Z

A = ℓ0 (x)dx = x + x dx = + =
0 0 2 2 3 2 0 12
Z 1 Z 1  3 1
2
 x 2 4
B = ℓ1 (x)dx = − x + 2x dx = − +x =−
0 0 3 0 3
Z 1 Z 1  3 1
1 2  1 x 3x2 23
C = ℓ2 (x)dx = x + 3x + 2 dx = + + 2x =
0 0 2 2 3 2 0 12
Hence
1
5 4 23
Z
f (x)dx ≈ f (−2) − f (−1) + f (0)
0 12 3 12
If f (x) = sin πx, then
Z 1
5 4 23
sin πxdx ≈ sin(−2π) − sin(−π) + sin(0) = 0
0 12 3 12
8 W EEK 6

where as the exact value is


1 h cos πx i1 2
Z
sin πxdx = − =
0 π 0 π

This shows that the quadrature formula gives a value of zero if used on a function that
vanishes at each node.

6.2 Method of Undetermined Coefficients

Another method of finding a numerical integral formula is by the finding the undetermined
coefficients. To illustrate this, let’s look at some examples.

Example 6.6. Determine values for A, B, and C that makes the formula
Z 2
xf (x)dx ≈ Af (0) + Bf (1) + Cf (2)
0

exact for all polynomials of degree ≤ 2.

Solution
The standard basis for polynomials of degree ≤ 2 is 1, x, x2 . So we have:


Z 2
f (x) = 1 LHS = xdx = 2, RHS = A + B + C
0
2
8
Z
f (x) = x LHS = x2 dx = , RHS = B + 2C
0 3
Z 2
2
f (x) = x LHS = x3 dx = 4, RHS = B + 4C
0

Setting LHS = RHS for each f (x) and solving for A, B and C simultaneously, we get A = 0,
B = 34 and C = 32 . Hence
2
4 2
Z
xf (x)dx ≈ f (1) + f (2)
0 3 3

Example 6.7. Find the formula


Z 1
f (x)dx ≈ A0 f (0) + A1 f (1)
0
W EEK 6 9

that is exact for all functions of the form f (x) = aex + b cos(πx/2).

Solution
Here the basis for f (x) is {ex , cos(πx/2)}. So we have
Z 1
f (x) = ex LHS = ex dx = e − 1, RHS = A0 + A1 e
0
1
2
Z
f (x) = cos(πx/2) LHS = cos(πx/2)dx = , RHS = A0
0 π

Setting LHS = RHS for each f (x) and solving for A0 and A1 simultaneously, we get
2
2 e−1− π 1 2
A0 = and A1 = =1− −
π e e πe
Hence
1  
2 1 2
Z
f (x)dx ≈ f (0) + 1 − − f (1)
0 π e πe

Example 6.8. Find the formula of the form


Z 2π
f (x)dx ≈ A1 f (0) + A2 f (π)
0

that is exact for any functions of the form f (x) = a + b cos x.

Solution
Here the basis for f (x) is {1, cos x}. So we have
Z 2π
f (x) = 1 LHS = 1dx = 2π, RHS = A1 + A2
0
Z 2π
f (x) = cos x LHS = cos xdx = 0 RHS = A1 − A2
0

Setting LHS = RHS for each f (x) and solving for A1 and A2 simultaneously, we get

A1 = A2 = π

Hence
Z 2π
f (x)dx ≈ π[f (0) + f (π)]
0

is exact for any functions of the form f (x) = a + b cos x.


10 W EEK 6

Example 6.9. Find a formula of the form


Z 1
1 2
 
f (x)dx ≈ A0 f (0) + A1 f 3 + A2 f 3 + A3 f (1)
0

that is exact for all polynomials of degree ≤ 3.

Solution
The standard basis for polynomials of degree ≤ 3 is 1, x, x2 , x3 . So we have:


Z 1
f (x) = 1 LHS = 1dx = 1, RHS = A0 + A1 + A2 + A3
0
1
1 1 2
Z
f (x) = x LHS = xdx = , RHS = A1 + A2 + A3
0 2 3 3
Z 1
1 1 4
f (x) = x2 LHS = x2 dx = , RHS = A1 + A2 + A3
0 3 9 9
Z 1
1 1 8
f (x) = x3 LHS = x3 dx = , RHS = A1 + A2 + A3
0 4 27 27

Solving for A0 , A1 , A2 , and A3 simultaneously, we get:

1 3 3 1
A0 = , A1 = , A2 = , A3 =
8 8 8 8
Hence
1    
1 3 1 3 2 1
Z
f (x)dx ≈ f (0) + f + f + f (1)
0 8 8 3 8 3 8

Вам также может понравиться