Numerical Calculus IV

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

MATH2033 (2023–2024)

Introduction to Scientific Computation

Numerical Calculus IV

Department of Mathematical Sciences


Numerical Calculus IV 2/30

Composite Numerical Integration


For appropriate functions f and intervals [a, b], we can approximate the
integral
b
∫ f (x) dx
a
by dividing the interval [a, b] into n subintervals [xi−1 , xi ] so that
b n xi
∫ f (x) dx = ∑ ∫ f (x) dx
a i=1 xi−1

and using a numerical integration rule to approximate


xi
∫ f (x) dx
xi−1

for all positive integers i such that i ≤ n.


Numerical Calculus IV 3/30

Composite Trapezoidal Rule


Suppose that n is a positive integer, that a ∈ R, that b ∈ R and that a < b.
b−a
Let h = and let xi = a + ih for all nonnegative integers i such that
n
i ≤ n.
For appropriate functions f , by the trapezoidal rule,
b n xi
∫ f (x) dx = ∑ ∫ f (x) dx
a i=1 xi−1
n
h
≈ ∑ (f (xi−1 ) + f (xi ))
i=1 2
h n
= ∑(f (xi−1 ) + f (xi ))
2 i=1
h
= (f (x0 ) + 2f (x1 ) + 2f (x2 ) + ⋯ + 2f (xn−1 ) + f (xn ))
2
n−1
h
= (f (a) + 2 ∑ f (xi ) + f (b)) .
2 i=1
Numerical Calculus IV 4/30

We have arrived at the composite trapezoidal rule (also called composite


trapezium rule)

b n−1
h
∫ f (x) dx ≈ (f (a) + 2 ∑ f (xi ) + f (b))
a 2 i=1

which uses the values of f at n + 1 evenly spaced points (or uses n


subintervals of equal length or uses n strips of equal width).
Numerical Calculus IV 5/30

Composite Midpoint Rule


Suppose that n is a positive integer, that a ∈ R, that b ∈ R and that a < b
b−a
Let h = and let xi = a + 2ih for all nonnegative integers i such that
2n
i ≤ n.
For appropriate functions f , by the midpoint rule,
b n xi
∫ f (x) dx = ∑ ∫ f (x) dx
a i=1 xi−1
n
≈ ∑ 2hf (xi−1 + h)
i=1
n
= 2h ∑ f (xi−1 + h).
i=1
We have arrived at the composite midpoint rule
b n
∫ f (x) dx ≈ 2h ∑ f (xi−1 + h)
a i=1
which uses the values of f at n evenly spaced points.
Numerical Calculus IV 6/30

Composite Simpson’s Rule


Suppose that n is a positive integer, that a ∈ R, that b ∈ R and that a < b
b−a
Let h = and let xi = a + 2ih for all nonnegative integers i such that
2n
i≤n
Numerical Calculus IV 7/30

For appropriate functions f , by Simpson’s rule,


b n xi
∫ f (x) dx = ∑ ∫ f (x) dx
a i=1 xi−1
n
h
≈ ∑ (f (xi−1 ) + 4f (xi−1 + h) + f (xi ))
i=1 3
h n
= ∑(f (xi−1 ) + 4f (xi−1 + h) + f (xi ))
3 i=1
h
= (f (x0 ) + 4f (x0 + h) + 2f (x1 ) + 4f (x1 + h) + 2f (x2 )
3
+4f (x2 + h) + ⋯ + 2f (xn−1 ) + 4f (xn−1 + h) + f (xn ))
n−1 n−1
h
= (f (a) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (b)) .
3 i=0 i=1
Numerical Calculus IV 8/30

We have arrived at the composite Simpson’s rule

b n−1 n−1
h
∫ f (x) dx ≈ (f (a) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (b))
a 3 i=0 i=1

which uses the values of f at 2n + 1 evenly spaced points.


Numerical Calculus IV 9/30

Problem 1
Let f be given by f (x) = sin(πx).
1
Approximate ∫ f (x) dx using the composite trapezoidal rule with
0
f being evaluated at 5 evenly spaced points.
1
Approximate ∫ f (x) dx using the composite midpoint rule with f
0
being evaluated at 5 evenly spaced points.
1
Approximate ∫ f (x) dx using the composite Simpson’s rule with f
0
being evaluated at 5 evenly spaced points.
Numerical Calculus IV 10/30

Using the composite trapezoidal rule with f being evaluated at 5 evenly


spaced points yields, where h = 0.25,
1
∫ sin(πx) dx
0
h
≈ (f (0) + 2(f (0.25) + f (0.5) + f (0.75)) + f (1))
2
= 0.125(sin(0) + 2(sin(0.25π) + sin(0.5π) + sin(0.75π)) + sin(π))
= 0.60355 . . . .
Using the composite midpoint rule with f being evaluated at 5 evenly
spaced points yields, where h = 0.1,
1
∫ sin(πx) dx
0
≈ 2h(f (0.1) + f (0.3) + f (0.5) + f (0.7) + f (0.9))
= 0.2(sin(0.1π) + sin(0.3π) + sin(0.5π) + sin(0.7π) + sin(0.9π))
= 0.64721 . . . .
Numerical Calculus IV 11/30

Using the composite Simpson’s rule with f being evaluated at 5 evenly


spaced points yields, where h = 0.25,
1
∫ sin(πx) dx
0
h
≈ (f (0) + 4(f (0.25) + f (0.75)) + 2f (0.5) + f (1))
3
1
= (sin(0) + 4(sin(0.25π) + sin(0.75π)) + 2 sin(0.5π) + sin(π))
12
= 0.63807 . . . .

Note that
1 1
1 1 1 2
∫ sin(πx) dx = [− cos(πx)] = − cos(π)+ cos(0) = = 0.63661 . . . .
0 π 0 π π π
Numerical Calculus IV 12/30

The error identity for the composite trapezoidal rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b, that f ∈ C 2 [a, b] and that n is
b−a
a positive integer. Let h = and let xi = a + ih for all nonnegative
n
integers i such that i ≤ n. Then there exists ξ ∈ (a, b) for which

b n−1
h b − a 2 ′′
∫ f (x) dx = (f (a) + 2 ∑ f (xi ) + f (b)) − h f (ξ).
a 2 i=1 12
Numerical Calculus IV 13/30

Proof By the error identity for the trapezoidal rule, for all positive
integers i such that i ≤ n, there exists ξi ∈ (xi−1 , xi ) for which
b n xi
∫ f (x) dx = ∑ ∫ f (x) dx
a i=1 xi−1
n
h3
= ∑ ( (f (xi−1 ) + f (xi )) − f ′′ (ξi ))
h
i=1 2 12
h n h3 n ′′
= ∑(f (xi−1 ) + f (xi )) − ∑ f (ξi )
2 i=1 12 i=1
n−1
h nh 2 1 n ′′
= (f (a) + 2 ∑ f (xi ) + f (b)) − h ∑ f (ξi )
2 i=1 12 n i=1
n−1
h b − a 2 1 n ′′
= (f (a) + 2 ∑ f (xi ) + f (b)) − h ∑ f (ξi )
2 i=1 12 n i=1

because nh = b − a.
Numerical Calculus IV 14/30

Now, for all positive integers i such that i ≤ n,

min f ′′ (x) ≤ f ′′ (ξi ) ≤ max f ′′ (x).


x∈[a,b] x∈[a,b]

Hence,
n
n min f ′′ (x) ≤ ∑ f ′′ (ξi ) ≤ n max f ′′ (x)
x∈[a,b] i=1 x∈[a,b]

and
1 n ′′
min f ′′ (x) ≤ ′′
∑ f (ξi ) ≤ max f (x).
x∈[a,b] n i=1 x∈[a,b]
Numerical Calculus IV 15/30

If
1 n ′′ ′′
∑ f (ξi ) = min f (x)
n i=1 x∈[a,b]

then
f ′′ (ξi ) = min f ′′ (x)
x∈[a,b]

for all positive integers i such that i ≤ n and, for all positive integers j
such that j ≤ n,

1 n ′′ 1 n ′′ ′′
∑ f (ξi ) = ∑ f (ξj ) = f (ξj ).
n i=1 n i=1
Numerical Calculus IV 16/30

If
1 n ′′ ′′
∑ f (ξi ) = max f (x)
n i=1 x∈[a,b]

then
f ′′ (ξi ) = max f ′′ (x)
x∈[a,b]

for all positive integers i such that i ≤ n and, for all positive integers j
such that j ≤ n,

1 n ′′ 1 n ′′ ′′
∑ f (ξi ) = ∑ f (ξj ) = f (ξj ).
n i=1 n i=1
Numerical Calculus IV 17/30

If
1 n ′′
min f ′′ (x) ≠ ′′
∑ f (ξi ) ≠ max f (x)
x∈[a,b] n i=1 x∈[a,b]

then
1 n ′′
min f ′′ (x) < ′′
∑ f (ξi ) < max f (x)
x∈[a,b] n i=1 x∈[a,b]

and so, since f ∈ C 2 [a, b], by the Intermediate Value Theorem there
exists c ∈ (min{c1 , c2 }, max{c1 , c2 }) for which

1 n ′′
f ′′ (c) = ∑ f (ξi )
n i=1

where c1 is such that c1 ∈ [a, b] and f ′′ (c1 ) = min f ′′ (x) and c2 is such
x∈[a,b]
that c2 ∈ [a, b] and f ′′ (c2 ) = max f ′′ (x).
x∈[a,b]
Numerical Calculus IV 18/30

Therefore, there exists ξ ∈ (a, b) for which

1 n ′′
f ′′ (ξ) = ∑ f (ξi )
n i=1

and
b n−1
h b − a 2 ′′
∫ f (x) dx = (f (a) + 2 ∑ f (xi ) + f (b)) − h f (ξ).
a 2 i=1 12
Numerical Calculus IV 19/30

The error identity for the composite midpoint rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b, that f ∈ C 2 [a, b] and that n is
b−a
a positive integer. Let h = and let xi = a + 2ih for all nonnegative
2n
integers i such that i ≤ n. Then there exists ξ ∈ (a, b) for which
b n
b − a 2 ′′
∫ f (x) dx = 2h ∑ f (xi−1 + h) + h f (ξ).
a i=1 6
Numerical Calculus IV 20/30

The error identity for the composite Simpson’s rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b, that f ∈ C 4 [a, b] and that n is
b−a
a positive integer. Let h = and let xi = a + 2ih for all nonnegative
2n
integers i such that i ≤ n. Then there exists ξ ∈ (a, b) for which

b n−1 n−1
h
∫ f (x) dx = (f (a) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (b))
a 3 i=0 i=1
b − a 4 (4)
− h f (ξ).
180
Numerical Calculus IV 21/30

Problem 2
1
Suppose that n is a positive integer. Let h = and let xi = ih for all
n
nonnegative integers i such that i ≤ n. Let f be given by f (x) = sin(πx).
Given that there exists ξ ∈ (0, 1) for which

1 n−1
h2
(f (0) + 2 ∑ f (xi ) + f (1)) − f ′′ (ξ),
h
∫ f (x) dx =
0 2 i=1 12

determine an integer m which is such that taking n ≥ m will guarantee


that
1 n−1
h
∣∫ f (x) dx − (f (0) + 2 ∑ f (xi ) + f (1))∣ < 0.0001.
0 2 i=1
Numerical Calculus IV 22/30

We have that
1 n−1
h
∣∫ f (x) dx − (f (0) + 2 ∑ f (xi ) + f (1))∣
0 2 i=1
1 2 ′′
= ∣− h f (ξ)∣ for some ξ ∈ (0, 1)
12
h2
≤ max ∣f ′′ (x)∣
12 x∈[0,1]
1
= max ∣−π 2 sin(πx)∣
12n2 x∈[0,1]
π2
= .
12n2
Numerical Calculus IV 23/30

Now, since n is positive,

π2 2 π2 π
2
< 0.0001 ⇔ n > ⇔n> √ .
12n 0.0012 0.0012
π
Moreover, √ = 90.6899 . . . and so taking n ≥ m with m = 91
0.0012
guarantees that

1 n−1
h
∣∫ f (x) dx − (f (0) + 2 ∑ f (xi ) + f (1))∣ < 0.0001.
0 2 i=1
Numerical Calculus IV 24/30

Problem 3
1
Suppose that n is a positive integer. Let h = and let xi = 2ih for all
2n
nonnegative integers i such that i ≤ n. Let f be given by f (x) = sin(πx).
Given that there exists ξ ∈ (0, 1) for which
1 n
h2 ′′
∫ f (x) dx = 2h ∑ f (xi−1 + h) + f (ξ),
0 i=1 6

determine an integer m which is such that taking n ≥ m will guarantee


that
1 n
∣∫ f (x) dx − 2h ∑ f (xi−1 + h)∣ < 0.0001.
0 i=1
Numerical Calculus IV 25/30

We have that
1 n
h2 ′′
∣∫ f (x) dx − 2h ∑ f (xi−1 + h)∣ = ∣ f (ξ)∣ for some ξ ∈ (0, 1)
0 i=1 6
h2
≤ max ∣f ′′ (x)∣
6 x∈[0,1]
1
= max ∣−π 2 sin(πx)∣
24n2 x∈[0,1]
π2
= .
24n2
Numerical Calculus IV 26/30

Now, since n is positive,

π2 2 π2 π
2
< 0.0001 ⇔ n > ⇔n> √ .
24n 0.0024 0.0024
π
Moreover, √ = 64.1274 . . . and so taking n ≥ m with m = 65
0.0024
guarantees that
1 n
∣∫ f (x) dx − 2h ∑ f (xi−1 + h)∣ < 0.0001.
0 i=1
Numerical Calculus IV 27/30

Problem 4
1
Suppose that n is a positive integer. Let h = and let xi = 2ih for all
2n
nonnegative integers i such that i ≤ n. Let f be given by f (x) = sin(πx).
Given that there exists ξ ∈ (0, 1) for which

1 n−1 n−1
h
∫ f (x) dx = (f (0) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (1))
0 3 i=0 i=1
h4 (4)
− f (ξ),
180
determine an integer m which is such that taking n ≥ m will guarantee
that
1 n−1 n−1
h
∣∫ f (x) dx − (f (0) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (1))∣ < 0.0001.
0 3 i=0 i=1
Numerical Calculus IV 28/30

We have that
1 n−1 n−1
h
∣∫ f (x) dx − (f (0) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (1))∣
0 3 i=0 i=1
h4 (4)
= ∣− f (ξ)∣ for some ξ ∈ (0, 1)
180
h4
≤ max ∣f (4) (x)∣
180 x∈[0,1]
1
= max ∣π 4 sin(πx)∣
2880n4 x∈[0,1]
π4
= .
2880n4
Numerical Calculus IV 29/30

Now, since n is positive,

π4 4 π4 π
4
< 0.0001 ⇔ n > ⇔n> .
2880n 0.288 0.2881/4
π
Moreover, = 4.2884 . . . and so taking n ≥ m with m = 5
0.2881/4
guarantees that

1 n−1 n−1
h
∣∫ f (x) dx − (f (0) + 4 ∑ f (xi + h) + 2 ∑ f (xi ) + f (1))∣ < 0.0001.
0 3 i=0 i=1
Numerical Calculus IV 30/30

References
Burden, Faires & Burden, Numerical Analysis, 10E
Section 4.4

You might also like