Академический Документы
Профессиональный Документы
Культура Документы
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.
Introduction
Numerical integration is the process of producing a numerical value for the integration of a
function over a set.
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.
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
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.
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
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
b
b−a
Z
f (x)dx ≈ [f (a) + f (b)]
a 2
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
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
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
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
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
This shows that the quadrature formula gives a value of zero if used on a function that
vanishes at each node.
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
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
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
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
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
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