0% found this document useful (0 votes)
16 views28 pages

Numerical Calculus III

Uploaded by

王健
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views28 pages

Numerical Calculus III

Uploaded by

王健
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

MATH2033 (2023–2024)

Introduction to Scientific Computation

Numerical Calculus III

Department of Mathematical Sciences


Numerical Calculus III 2/28

The midpoint rule


For appropriate functions f and intervals [a, b], we can approximate the
integral
b
∫ f (x) dx
a
using the midpoint rule
b a+b
∫ f (x) dx ≈ (b − a)f ( ).
a 2
Numerical Calculus III 3/28

The trapezoidal rule


For appropriate functions f and intervals [a, b], we can approximate the
integral
b
∫ f (x) dx
a
using the trapezoidal rule
b b−a
∫ f (x) dx ≈ (f (a) + f (b)).
a 2
Numerical Calculus III 4/28

Simpson’s rule
For appropriate functions f and intervals [a, b], we can approximate the
integral
b
∫ f (x) dx
a
using Simpson’s rule
b b−a a+b
∫ f (x) dx ≈ (f (a) + 4f ( ) + f (b)) .
a 6 2
Numerical Calculus III 5/28

Problem 1
Let f be given by f (x) = 1 − x − x2 .
1
Compute an approximation to ∫ f (x) dx using the midpoint rule.
0
1
Compute an approximation to ∫ f (x) dx using the trapezoidal rule.
0
1
Compute an approximation to ∫ f (x) dx using Simpson’s rule.
0
Compute the absolute error in each of the obtained approximations
1
to ∫ f (x) dx.
0
Numerical Calculus III 6/28

We can compute that f (0) = 1, f (0.5) = 0.25 and f (1) = −1. An


1
approximation to ∫ f (x) dx obtained using the midpoint rule is
0

(1 − 0)f (0.5) = 0.25.


1
An approximation to ∫ f (x) dx obtained using the trapezoidal rule is
0
1−0 1
(f (0) + f (1)) = (1 + (−1)) = 0.
2 2
1
An approximation to ∫ f (x) dx obtained using Simpson’s rule is
0
1−0 1 1
(f (0) + 4f (0.5) + f (1)) = (1 + 1 + (−1)) = .
6 6 6
We have that
1 1 1
1 1 1 1 1
∫ f (x) dx = ∫ (1 − x − x2 ) dx = [x − x2 − x3 ] = 1 − − = .
0 0 2 3 0 2 3 6
Numerical Calculus III 7/28

Hence, the absolute error in the approximation obtained using the


midpoint rule is
1
∣ − 0.25∣ = 0.08333 . . . ,
6
the absolute error in the approximation obtained using the trapezoidal
rule is
1
∣ − 0∣ = 0.16666 . . .
6
and the absolute error in the approximation obtained using Simpson’s rule
is
1 1
∣ − ∣ = 0.
6 6
Numerical Calculus III 8/28

Numerical integration rules


For appropriate functions f , intervals [a, b] and distinct points
x0 , x1 , . . . , xn , where n is a positive integer, we can derive a numerical
integration (also called quadrature) rule that can be used to approximate
b
∫ f (x) dx using no more of the values of f than
a
f (x0 ), f (x1 ), . . . , f (xn ).
Such a rule can be arrived at by taking
b b
∫ f (x) dx ≈ ∫ pn (x) dx
a a

where pn is the polynomial of degree at most n that interpolates f at the


n + 1 points x0 , x1 , . . . , xn .
b b
Note that ∫ f (x) dx = ∫ pn (x) dx if f is a polynomial of degree n or
a a
less.
Numerical Calculus III 9/28

The trapezoidal rule can be arrived at by taking n = 1, x0 = a and x1 = b.


a+b
Simpson’s rule can be arrived at by taking n = 2, x0 = a, x1 = and
2
x2 = b.
Numerical Calculus III 10/28

Problem 2
For appropriate functions f and intervals [a, b], derive the trapezoidal rule
b
for approximating ∫ f (x) dx by integrating an appropriate polynomial.
a

The polynomial of degree at most 1 that interpolates f at the points a


and b is given by
x−b x−a
p1 (x) = f (a) + f (b) .
a−b b−a
Numerical Calculus III 11/28

Moreover,
b b
1 1 1 1
∫ p1 (x) dx = [f (a) ( x2 − bx) + f (b) ( x2 − ax)]
a a−b 2 b−a 2 a
1 1 2 2 1 1 2
= f (a) ( b − b ) + f (b) ( b − ab)
a−b 2 b−a 2
1 1 1 1
−f (a) ( a2 − ab) − f (b) ( a2 − a2 )
a−b 2 b−a 2
1 1 2 1 2
= f (a) (− b − a + ab)
a−b 2 2
1 1 2 1
+f (b) ( b − ab + a2 )
b−a 2 2
1 1 2 2 1 1 2
= f (a) (b + a − 2ab) + f (b) (b − 2ab + a2 )
b−a2 b−a2
1 1 1 1
= f (a) (b − a)2 + f (b) (b − a)2
b−a2 b−a2
b−a
= (f (a) + f (b)).
2
Numerical Calculus III 12/28

We have arrived at the trapezoidal rule


b b−a
∫ f (x) dx ≈ (f (a) + f (b)).
a 2
Numerical Calculus III 13/28

Degree of accuracy
The degree of accuracy (also called degree of precision) of a numerical
integration rule is the largest nonnegative integer n for which the rule is
exact for all polynomials of degree at most n.
The degree of accuracy of the trapezoidal rule is 1.
The degree of accuracy of Simpson’s rule is 3.
Numerical Calculus III 14/28

Problem 3
Determine the degree of accuracy of the midpoint rule.

With f0 (x) = 1 we have that


b
∫ f0 (x) dx = [x]ba = b − a
a

and
a+b b
(b − a)f0 ( ) = b − a = ∫ f0 (x) dx.
2 a
With f1 (x) = x we have that
b b
1 1
∫ f1 (x) dx = [ x2 ] = (b2 − a2 )
a 2 a 2
and
a+b a+b 1 2 b
(b − a)f1 ( ) = (b − a) = (b − a2 ) = ∫ f1 (x) dx.
2 2 2 a
Numerical Calculus III 15/28

So, with f (x) = c0 f0 (x) + c1 f1 (x) where c0 and c1 are constants we have
that
a+b a+b a+b
(b − a)f ( ) = (b − a) (c0 f0 ( ) + c1 f1 ( ))
2 2 2
a+b a+b
= c0 (b − a)f0 ( ) + c1 (b − a)f1 ( )
2 2
b b
= c0 ∫ f0 (x) dx + c1 ∫ f1 (x) dx
a a
b
= ∫ (c0 f0 (x) + c1 f1 (x)) dx
a
b
= ∫ f (x) dx.
a

Hence, the midpoint rule is exact for all polynomials of degree at most 1.
Numerical Calculus III 16/28

With f2 (x) = x2 we have that


b b
1 1
∫ f2 (x) dx = [ x3 ] = (b3 − a3 )
a 3 a 3
and
a+b a2 + 2ab + b2 1 3
(b − a)f2 ( ) = (b − a) = (b − a3 − a2 b + ab2 ).
2 4 4
Hence, the midpoint rule is not exact for all polynomials of degree 2.
Therefore, the degree of accuracy of the midpoint rule is 1.
Numerical Calculus III 17/28

Theorem (Weighted Mean Value Theorem for Integrals)


Suppose that a ∈ R, that b ∈ R and that a < b. Suppose that f is a
function that is real-valued and continuous on [a, b] and that g is a
function that is Riemann integrable on [a, b] and such that

g(x) ≥ 0 for all x ∈ [a, b]

or
g(x) ≤ 0 for all x ∈ [a, b].
Then there exists ξ ∈ (a, b) for which
b b
∫ f (x)g(x) dx = f (ξ) ∫ g(x) dx.
a a
Numerical Calculus III 18/28

The error identity for the trapezoidal rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b and that f ∈ C 2 [a, b]. Let
h = b − a. Then there exists ξ ∈ (a, b) for which
b h3
(f (a) + f (b)) − f ′′ (ξ).
h
∫ f (x) dx =
a 2 12
Proof Let p be given by
1 h 2 h2
p(x) = (x − a − ) − .
2 2 8
Then
p′ (x) = x − a −
h
2
and
p′′ (x) = 1.
Numerical Calculus III 19/28

Moreover,

1 h 2 h2 1 h 2 h2 1 h 2 h2 h2 h2
p(b) = (b − a − ) − = (h − ) − = ( ) − = − = 0,
2 2 8 2 2 8 2 2 8 8 8

1 h 2 h2 1 h 2 h2 h2 h2
p(a) = (a − a − ) − = (− ) − = − = 0,
2 2 8 2 2 8 8 8

p′ (b) = b − a − = h − =
h h h
2 2 2
and
p′ (a) = a − a −
h h
=− .
2 2
Numerical Calculus III 20/28

Integration by parts yields that


b b
∫ f (x) dx = ∫ f (x)p′′ (x) dx
a a
b
= [f (x)p′ (x)]a − ∫ f ′ (x)p′ (x) dx
b
a
b
= f (b)p (b) − f (a)p′ (a) − ∫

f ′ (x)p′ (x) dx
a
b
= f (b) + f (a) − ∫ f ′ (x)p′ (x) dx
h h
2 2 a
b
(f (a) + f (b)) − ∫ f ′ (x)p′ (x) dx.
h
=
2 a
Numerical Calculus III 21/28

Moreover,
b b
f ′ (x)p′ (x) dx = − [f ′ (x)p(x)]a + ∫ f ′′ (x)p(x) dx
b
−∫
a a
b
′ ′
= −f (b)p(b) + f (a)p(a) + ∫ f ′′ (x)p(x) dx
a
b
= ∫ f ′′ (x)p(x) dx.
a

Now, since p(x) ≤ 0 for all x ∈ [a, b], by the Weighted Mean Value
Theorem for Integrals, there exists ξ ∈ (a, b) for which
b b
∫ f ′′ (x)p(x) dx = f ′′ (ξ) ∫ p(x) dx.
a a
Numerical Calculus III 22/28

Furthermore,
b
b 1 h 3 h2
∫ p(x) dx = [ (x − a − ) − x]
a 6 2 8 a
1 h 3 h2 1 h 3 h2
= (b − a − ) − b − (a − a − ) + a
6 2 8 6 2 8
3 2 3
1 h h 1 h
= (h − ) − (b − a) − (− )
6 2 8 6 2
1 h 3 h3 1 h3
= ( ) − +
6 2 8 6 8
1 h3 5 h3
= −
6 8 6 8
2 h3
= −
3 8
h3
= − .
12
Numerical Calculus III 23/28

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


b h3
(f (a) + f (b)) − f ′′ (ξ).
h
∫ f (x) dx =
a 2 12
Numerical Calculus III 24/28

Problem 4
Suppose that a ∈ R, that b ∈ R, that a < b and that f ∈ C 2 [a, b]. Let
h = b − a. Determine an upper bound on
b h
∣∫ f (x) dx − (f (a) + f (b))∣ .
a 2
Numerical Calculus III 25/28

By the error identity for the trapezoidal rule, there exists ξ ∈ (a, b) for
which
b h h3 ′′
∫ f (x) dx − (f (a) + f (b)) = − f (ξ)
a 2 12
and hence
b h3 h3 ′′
f (x) dx − (f (a) + f (b))∣ = ∣− f ′′ (ξ)∣ =
h
∣∫ ∣f (ξ)∣ .
a 2 12 12

Consequently,
b h3
max ∣f ′′ (c)∣ .
h
∣∫ f (x) dx − (f (a) + f (b))∣ ≤
a 2 12 c∈[a,b]
Numerical Calculus III 26/28

The error identity for the midpoint rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b and that f ∈ C 2 [a, b]. Let
b−a
h= . Then there exists ξ ∈ (a, b) for which
2
b h3 ′′
∫ f (x) dx = 2hf (a + h) + f (ξ).
a 3
Numerical Calculus III 27/28

The error identity for Simpson’s rule


Theorem
Suppose that a ∈ R, that b ∈ R, that a < b and that f ∈ C 4 [a, b]. Let
b−a
h= . Then there exists ξ ∈ (a, b) for which
2
b h5
(f (a) + 4f (a + h) + f (b)) − f (4) (ξ).
h
∫ f (x) dx =
a 3 90
Numerical Calculus III 28/28

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

You might also like