43 Numerical Integration Problem 1 F X PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

4.

3 - Numerical Integration

Problem (1): Given a function fx continuous on a, b, approximate numerically the definite integral
b
 a fx dx.
If we know an antiderivative Fx of fx, then by the Fundamental Theorem of Calculus we know
b
 a fx dx  Fb − Fa.
In cases where we we do not know Fx exactly, for example, fx  e −x , fx  cosx 2 , how can we
2

b
approximate  fxdx numerically?
a
b
Problem (2): Given a set of pairs x i , y i  mi0 where y i  fx i  and x i in a, b, approximate  fxdx by
a
m
I m f  ∑ c i fx i .
i0
b
We want to determine c i  mi0 so that  fxdx − I m f is as small as possible.
a

1. The Degree of Precision of a Quadrature Formula:


The degree of precision of a quadrature formula If is the largest positive integer n such that
b
 a x k dx  Ix k , k  0, 1, 2, . . . , n.
Note that a quadrature formula If with an nth degree of precision is exact for all polynomials of degree
n. So, the larger the value of n is, the better the approximation If is.

b b − a
Example  fxdx  9 hfa  h  3 hfb, h , 3h  b − a. Find the degree of
a 4 4 3
precision
of this quadrature formula If  9 hfa  h  3 hfb.
4 4
b
Consider fx  1, fx  x, fx  x 2 , . . . . It is known that  a x k dx  1 b k1 − a k1 .
k1
k fx 1 b k1 − a k1  9 hfa  h  3 hfb
k1 4 4
0 1 b−a 9 h  3 h  3h  b − a
4 4
9 ha  h  3 hb  3h 3a  h  b
1 x 1 b 2 − a 2  4 4 4
2 −
 b a 3a  b − a  b  b − a 2a  2b  1 b 2 − 1 a 2
4 4 2 2
2 x2 1 b3 − 1 a3 9 ha  h 2  3 hb 2  1 b 3 − 1 a 3
3 3 4 4 3 3

3 x3 1 b4 − 1 a4 9 ha  h 3  3 hb 3  − 1 ba 3  1 b 2 a 2 − 1 b 3 a  5 b 4 − 2 a 4
4 4 4 4 9 6 9 18 9
So the degree of precision is 2.

1
9 ha  h 2  3 hb 2  1 b − a3a 2  6ah  3h 2  b 2 
4 4 4
b − a 2
 1 b − a 3a 2  2ab − a   b2
4 3
 1 b − a 3a 2  2ab − 2a 2  b − 2ab  a  b 2
2 2
4 3
 1 b − a 4 a 2  4 ab  4 b 2
4 3 3 3
 1 b − aa 2  ab  b 2   1 b 3 − a 3 
3 3

Example Suppose that the quadrature formula


2
 0 fxdx  c 0 f0  c 1 f1  c 2 f2
is exact for all polynomials of degree less than and equal to 2. Find c 0 , c 1 and c 2 .
2
Let If  c 0 f0  c 1 f1  c 2 f2. Find c 0 , c 1 and c 2 so that  fxdx  Ix k  for k  0, 1, 2.
0
2
 0 x k dx  1 2 k1
k1
3 − 2: 2c 2  2 , c 2  1
3 3
k  0, fx  1, c0  c1  c2  2 1 Substitute it into 2 : c1  2 − 2 1  4
3 3
. k  1, fx  x, 0  c 1  2c 2  2 2
Substitute both c 1 and c 2 into 1 :
k  2, fx  x 2 , 0  c 1  4c 2  8 3
3 c0  2 − 4 − 1  1
3 3 3
2
 0 fxdx  f0  4 f1  1 f2
1
3 3 3
What is the exact degree of precision?
2
Check the case when k  3, fx  x 3 ,  x 3 dx  1
4
2 4  4,
0
2
If  1 f0  4 f1  1 f2  1 0 3  4 1 3  1 2 3  4 
3 3 3 3 3 3
 0 x 3 dx
2
Check the case when k  4, fx  x 4 ,  x 4 dx  1
5
25  32
5
0
2
If  1 f0  4 f1  1 f2  1 0 4  4 1 4  1 2 4  20 ≠
3 3 3 3 3 3 3
 0 x 4 dx
The degree of precision is 3.

2. Numerical Quadrature:
Another way to determine c i ’s for If : find P k x where k ≤ n such that fx ≈ P k x and then
n
b b
 a fxdx ≈  a P k xdx  ∑ c i fx i .
i0

The interpolating polynomial P n x that agrees with fx at x i , y i , i  0, . . . , n will be a good choice to
approximate fx.
a. Using Lagrangian Interpolating Polynomials:
2
Let P n x  ∑ i0 fx i L n,i x. Then
n

n n
f n1 c
fx  ∑ fx i L n,i x  x − x i 
i0
n  1! i0

and
n
b b b
a fxdx ≈ ∑ fx i   a L n,i xdx  ci   a L n,i xdx, i  0, 1, . . . , n
i0

The corresponding approximation error is


n
b f n1 c
R int  a n  1!
x − x i dx.
i0
Derived quadrature formulas are called Newton-Cotes Formulas. We will derive two formulas
below.
(1) Trapezoidal Rule:
Consider the interpolating polynomial P 1 x of degree 1 with data pairs a, fa and
b, fb . Let h  b − a.
P 1 x  fa x − b  fb x − a  −fa x − b  fb x − a
a−b b−a h h
b b b
 a P 1 xdx   a −fa x − b  fb x − a dx  −
h h
fa
2h
x − b 2 
fb
2h
x − a 2
a

 1 fbh 2  fah 2  h fb  fa


2h 2
(2) Simpson’s Rule:
Consider the interpolating polynomial P 2 x of degree 2 with data pairs
a, fa , a  h, fa  h and b, fb . Let h  b − a .
2
x − a − hx − b x − ax − b x − ax − a − h
P 2 x  fa  fa  h  fb
−h−2h h−h 2hh
fa fa  h fb
 2
x − a − hx − a − h − h − 2
x − ax − a − 2h  x − ax − a − h
2h h 2h 2
b b fa  h b
 a P 2 xdx  fa
2h 2  a
x − a − h 2
− hx − a − h dx −
h 2  a
x − a 2 − 2hx − a dx
fb b

2h 2 a
 x − a 2 − hx − a dx
fa 1 fa  h 1
 2
x − a − h 3 − h x − a − h 2 | ba − 2
x − a 3 − hx − a 2 | ba
2h 3 2 h 3
fb 1
 2
x − a 3 − h x − a 2 | ba
2h 3 2
fa 1 3 fa  h 1
 2
h − −h 3 − h h 2 − −h 2 − 2h 3 − h2h 2
2h 3 2 h2 3
fb 1
 2
2h 3 − h 2h 2
2h 3 2
 h fa − fa  h 8h − 4h  fb 4h − h
3 3 3
 h fa  4h fa  h  h fb
3 3 3
3
b. n  1 −point closed Newton - Cotes formulas:
x 0  a, x n  b, h  b− a
n , x i  a  ih

#
#
n of Quadrature Formula If approx c
of
sub- error
pts
int.
1 fx 0   1 fx 1  3 ′′
1 2 1 h − h f c x 0 , x 1 
2 2 12
5
2 3 2 h 1 fx 0   4 fx 1   1 fx 2  − h f 4 c x 0 , x 2 
3 3 3 90
5
3 4 3 h 3 fx 0   9 fx 1   9 fx 2   3 fx 3  − 3h f 4 c x 0 , x 3 
8 8 8 8 80
7
4 5 4 h 14 fx 0   64 fx 1   24 fx 2   64 fx 3   14 fx 4  − 8h f 6 c x 0 , x 4 
45 45 45 45 45 945
c. n  1 −point open Newton - Cotes formulas:
x n  b − h, x n1  b, h  b − a , x i  x i−1  h.
x −1  a, x 0  a  h,
n2
The Midpoint formulas are open Newton - Cotes formulas.

# #
n Quadrature Formula If approx c
of of
error
pts sub-int.

0 3 2 2hfx 0  h 3 f ′′ c x −1 , x 1 
3
1 4 3 h 3 fx 0   3 fx 1  3h 3 f ′′ c x −1 , x 2 
2 2 4
2 5 4 h 8 fx 0  − 4 fx 1   8 fx 2  14h 5 |f 4 c| x −1 , x 3 
3 3 3 45
3 6 5 h 55 fx 0   5 fx   5 fx 2   55 fx 3  95h 5 f 4 c x −1 , x 4 
24 24 1 24 24 144

Example Use the (i)Trapezoidal Rule (closed 2-point), (ii) Simpson’s Rule (closed 3-point) (iii) open
/4
4-point and (iv) open 5-point Newton-Cotes formulas to approximate  sinx 2 dx and
0
estimate the approximation errors, respectively.
Let fx  sinx 2 .
(i) Trapezoidal Rule (closed 2-point):
h   − 0   , x 0  0, x 1  
4 4 4
If  1  f0  f    0  sin 
2
 0. 227 164
2 4 4 8 16
(ii) Simpson’s Rule (closed 3-point):

4
h  1  − 0   , x 0  0, x 1   , x 2  
2 4 8 8 4
If  1  f0  4f   f   0  4 sin   sin 
2 2
 1  0. 156 147 238 2
3 8 8 4 3 8 64 16
(iii) open 4-point Newton-Cotes:
h  1    , x −1  0, x 0   , x1  0  2    , x2  
3 4 12 12 12 6 4
If  3  fx 0   fx 1    sin   sin 
2 2
 0. 133 211
2 12 8 12 6
(iv) open 5-point Newton-Cotes:
h  1    , x −1  0, x 0   , x 1   , x 2  3 , x 3  
4 4 16 16 8 16 4
If  4h 2fx 0  − fx 1   2fx 2   4   
2 2 2
2 sin − sin  2 sin 3
3 3 16 16 8 16
 0. 158 022
True errors:
/4
(i) R int  0 sinx 2 dx − 0. 227 164  7. 000 933 25  10 −2
/4
(ii) R int  0 sinx 2 dx − 0. 156 147 238 2  1. 007 429 271  10 −3
/4
(iii) R int  0 sinx 2 dx − 0. 133 211  2. 394 366 7  10 −2
/4
(iv) R int  0 sinx 2 dx − 0. 158 022  8. 673 325 2  10 −4

Approximation errors:
′ ′′
fx  sinx 2 , f x  2x cosx 2 , f x  2cosx 2  − 2x 2 sinx 2 
′′′
f x  2−2x sinx 2  − 4x sinx 2  − 4x 3 cosx 2   gx  −43x sinx 2   2x 3 cosx 2 
f 4 x  −43 sinx 2   6x 2 cosx 2   6x 2 cosx 2  − 4x 4 sinx 2   −43 − 4x 4  sinx 2   12x 2 cosx 2 

y
2.0 y
25

20
1.5

15

1.0
10

5
0.5

0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
x x
′′  4 
y  f x , x in 0, 4 y f x , x is in 0, 4

5
′′ ′′
f x ≤ f 0  2,

f
4
x ≤ f 
4
≤ 16 sin 
2
 4
− 48 cos 
2
 2
− 12 sin 
2

4 4 4 4 4 4
 27. 571 910 72 ≤ 28
3 ′′
(i) R int  − h f c ≤ 2  3
 8. 074 551  10 −2
12 12 4
(ii) R int  − h f 4 c ≤ 1 28 
5 5
 2. 905 46  10 −3
90 90 8
(iii) R int  3 h 3 f ′′ c ≤ 3 2  3  2. 691 517  10 −2
4 4 12
(iv) R int  14h f c ≤ 14 28  5  2. 542 277 79  10 −3
5 4
45 45 16

3. Approximation Errors:
Weighted Mean Value Theorem for Integrals:
b
Suppose that F is continuous on a, b ,  gxdx exists, and gx does not change sign on a, b .
a
Then there exists a number c in a, b with
b b
 a Fxgxdx  Fc  a gxdx.
The corresponding approximation error:
′′
Consider Fx  f c, and gx  x − ax − b. gx is a quadratic function which is zero at x  a
and x  b and gx  0 for x in a, b. So, gx does not change sign on a, b .
′′
b f c b
R trap  a 2!
x − ax − bdx  1 f c  x − ax − bdx
2
′′
a
b b
 1 f c  x − ax − a − hdx  1 f c  x − a 2 − x − ah dx
′′ ′′
2 a 2 a
′′ b ′′
 1 f c 1 x − a 3 − 1 x − a 2 h  1 f c 1 b − a 3 − 1 b − a 2 h
2 3 2 a 2 3 2
′′ ′′
 1 f c 1 h 3 − 1 h 3  − 1 f ch 3
2 3 2 12
′′
a. If f x ≤ M for all x in a, b , then
R trap ≤ M h 3
12

b. Using Taylor Polynomials and Newton Difference Formulas:


b
Though we can derive an numerical quadrature using the formula: ∑ i0 fx i   L n,i xdx, the
n
a
remainder formula
n
b f n1 c
R int  a n  1!
x − x i dx
i0

may not be easy to use to derive the approximation error. To derive the approximation error for the
Trapezoidal Rule, we use the Weighted Mean Value Theorem which has a condition: gx does
not change sign on a, b. This condition is not always satisfied for  i0 x − x i . For example, to
n

6
derive the approximation error for Simpson’s Rule (3 pairs of data, a 2nd degree Lagrangian
polynomial)
′′′
b c
R int  a f
3!
x − x 0 x − x 1 x − x 2 dx

Here gx  1 x − x 0 x − x 1 x − x 2  which does change sign over the interval x 0 , x 2 .
3!

By Taylor Theorem, we know


b b b
fx  P n x  R n x, and  a fxdx   a P n xdx   a R n xdx where
′ ′′ ′′′ n
f x i  f x i  f x i  f x i 
P n x  fx i   x − x i   x − x i  2  x − x i  3 . . .  x − x i  n
1! 2! 3! n!
n1
f c
R n x  x − x i  n1
n  1!
The approximation error for
b b
 a fxdx ≈  a P n xdx
is
n1
b c
R int  a f
n  1!
x − x i  n1 dx.

Observe that the sign of x − x i  n1 does not change on the interval a, b. So by the Weighted
Mean-Value Theorem we know there exists a number c in a, b such that
n1
b c f n1 c̄  b
a f
n  1!
x − x i  n1 dx 
n  1!
 a x − x i  n1 dx
f n1 c̄  1
 b − x i  n2 − a − x i  n2
n  1! n2
For the approximation error for Simpson’s Rule: choose x i  x 1 , and use x 0 , x 1 , x 2 :
x 0  a  x 1 − h, x 2  b  x 1  h, h  b − a
2
Note that the interval a, b  x 0 , x 2 is symmetric about x  x 1 . So,
x2 x1 x2
 x x − x 1  m dx   x x − x 1  m dx   x x − x 1  m dx
0 0 1

0 if m is odd
 x2
2  x − x 1  m dx  2 x − x 1  m1  2 h m1 if m is even
x 1 m1 2 m1
Consider
b b
 a fxdx ≈  a P 3 xdx
′ ′′ ′′′
x2 f x 1  f x 1  f x 1 
 x fx 1  
1!
x − x 1  
2!
x − x 1  2 
3!
x − x 1  3 dx
0

′′
f x 1  2 h3
 2hfx 1  
2 3

7
′′
Approximate f x 1  by the difference formula:
′′ fx  h − 2fx  fx − h
f x  − 1 f 4 c 1 h 2
h2 12
we have the numerical integral formula:
3 fx 2  − 2fx 1   fx 0 
If  2hfx 1   h  2hfx 1   h fx 2  − 2fx 1   fx 0 
3 h2 3
 h fx 0   4fx 1   fx 2 
3
and the approximation error:
4
x2 c 1 
x f 3
R int  x − x 1  4 dx − h 1 f 4 c 2 h 2
0 4! 3 12
4
c̄ 1 
f 2 h 5 − h 5 f 4 c 2   f 4 c 1 − 1 h 5  − h 5 f 4 c

4! 5 36 60 36 90
where c is in x 0 , x 2 .

Exercises:
1. Approximate the value of each of the following integrals using the Trapezoidal rule. Verify that the
theoretical error bound holds in each case.
2
a.  1x dx
1
1
b.  e −x dx
0
1
c.  1 dx
0 1  x2
1
d.  tan −1 x dx
0

2. Approximate the value of each of the integrals given in Exercise 1. using the Simpson’s rule. Verify that
the theoretical error bound holds in each case.

3. Approximate the value of each of the integrals given in Exercise 1. using the Midpoint rule. Verify that
the theoretical error bound holds in each case.

4. Show that the Midpoint rule has degree of precision equal to 1.

5. Show that the open Newton-Cotes formula with n  1 has degree of precision equal to 1.

6. (a) Determine values for the coefficients A 0 , A 1 and A 2 so that the quadrature formula
1
If   fxdx  A 0 f − 1  A 1 f0  A 2 f 1
−1 2 2
has degree of precision at least 2.
(b) Determine the exact degree of precision for the quadrature rule obtained in (a).

7. (a) Determine values for the coefficients A 0 , A 1 and A 2 so that the quadrature formula

8
1
If   −1 fxdx  A 0 f −1
3
 A1f 1
3
 A 2 f1
has degree of precision at least 2.
(b) Determine the exact degree of precision for the quadrature rule obtained in (a).

8. (a) Determine values for the coefficients A 0 , A 1 and x 1 so that the quadrature formula
1
If   −1 fxdx  A 0 f−1  A 1 fx 1 
has degree of precision at least 2.
(b) Determine the exact degree of precision for the quadrature rule obtained in (a).

b − a 3 ′′
9. Show that the error term for the midpoint rule is f c where c in a, b.
24

You might also like