Numerical Calculus I

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

MATH2033 (2023–2024)

Introduction to Scientific Computation

Numerical Calculus I

Department of Mathematical Sciences


Numerical Calculus I 2/21

Forward difference approximation


For appropriate functions f , points x0 and positive numbers h, we can
approximate
f ′ (x0 ) = lim
f (x0 + γ) − f (x0 )
γ→0 γ
by a forward difference approximation to f ′ (x0 ),

f (x0 + h) − f (x0 )
.
h
Numerical Calculus I 3/21

Backward difference approximation


For appropriate functions f , points x0 and positive numbers h, we can
approximate
f ′ (x0 ) = lim
f (x0 + γ) − f (x0 )
γ→0 γ
by a backward difference approximation to f ′ (x0 ),

f (x0 ) − f (x0 − h)
.
h
Note that
f (x0 − h) − f (x0 ) f (x0 ) − f (x0 − h)
= .
−h h
Numerical Calculus I 4/21

Problem 1
Let f be given by f (x) = x − x2 − x3 .
Compute a forward difference approximation to f ′ (0) using no more
of the values of f than f (0) and f (0.05).
Compute a backward difference approximation to f ′ (0) using no
more of the values of f than f (0) and f (−0.05).
Compute the absolute error in each of the obtained approximations
to f ′ (0).
Numerical Calculus I 5/21

We can compute that f (0) = 0, f (0.05) = 0.047375 and


f (−0.05) = −0.052375. A forward difference approximation to f ′ (0) is

f (0.05) − f (0) 0.047375


= = 0.9475.
0.05 0.05
A backward difference approximation to f ′ (0) is

f (0) − f (−0.05) 0.052375


= = 1.0475.
0.05 0.05
Now, f ′ (x) = 1 − 2x − 3x2 and so f ′ (0) = 1. Hence, the absolute error in
the obtained forward difference approximation to f ′ (0) is

∣1 − 0.9475∣ = 0.0525

and the absolute error in the obtained backward difference approximation


to f ′ (0) is
∣1 − 1.0475∣ = 0.0475.
Numerical Calculus I 6/21

Problem 2
Suppose that a ∈ R, that b ∈ R and that a < b. Suppose that f ∈ C 2 [a, b],
that x0 ∈ [a, b) and that the positive number h is such that
x0 + h ∈ (a, b].
Show that

f ′ (x0 ) − = − f ′′ (ξ) for some ξ ∈ (x0 , x0 + h).


f (x0 + h) − f (x0 ) h
h 2
Determine an upper bound on

∣f ′ (x0 ) −
f (x0 + h) − f (x0 )
∣.
h

Determine the positive integer m which is such that

f ′ (x0 ) −
f (x0 + h) − f (x0 )
= O(hm ).
h
Numerical Calculus I 7/21

By Taylor’s Theorem, there exists ξ ∈ (x0 , x0 + h) for which

f (x0 + h) = f (x0 ) + f ′ (x0 )(x0 + h − x0 ) + f ′′ (ξ)(x0 + h − x0 )2


1
2
′ 1 ′′ 2
= f (x0 ) + f (x0 )h + f (ξ)h
2
and hence
h2 ′′
f ′ (x0 )h − (f (x0 + h) − f (x0 )) = − f (ξ).
2
Consequently,

f ′ (x0 ) − = − f ′′ (ξ) for some ξ ∈ (x0 , x0 + h).


f (x0 + h) − f (x0 ) h
h 2
Numerical Calculus I 8/21

Moreover

∣f ′ (x0 ) − ∣ = ∣− f ′′ (ξ)∣ = ∣f ′′ (ξ)∣


f (x0 + h) − f (x0 ) h h
h 2 2

and so, since ξ ∈ (x0 , x0 + h),

∣f ′ (x0 ) − max ∣f ′′ (x)∣ .


f (x0 + h) − f (x0 ) h
∣≤
h 2 x∈[x0 ,x0 +h]
Numerical Calculus I 9/21

Furthermore,

∣f ′ (x0 ) − max ∣f ′′ (x)∣ ≤ max ∣f ′′ (x)∣ = Ch


f (x0 + h) − f (x0 ) h h
∣≤
h 2 x∈[x0 ,x0 +h] 2 x∈[a,b]

where
max ∣f ′′ (x)∣ .
1
C=
2 x∈[a,b]
Therefore,
f ′ (x0 ) −
f (x0 + h) − f (x0 )
= O(hm )
h
where
m = 1.
Numerical Calculus I 10/21

Formulas for approximating derivatives


For appropriate functions f and distinct points x0 , x1 , . . . , xn , where n is
a positive integer, we can derive a formula that can be used to
approximate f (m) (x0 ), where m is a positive integer that is at most n,
using no more of the values of f than f (x0 ), f (x1 ), . . . , f (xn ).
Such a formula can be arrived at by taking

f (m) (x0 ) ≈ p(m)


n (x0 )

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


n + 1 points x0 , x1 , . . . , xn .
(m)
Note that f (m) (x0 ) = pn (x0 ) if f is a polynomial of degree n or less.
Numerical Calculus I 11/21

Central difference approximations


For appropriate functions f , points x0 and positive numbers h, the
polynomial of degree at most 2 that interpolates f at the points x0 − h,
x0 and x0 + h is given by
(x − x0 )(x − (x0 + h))
p2 (x) = f (x0 − h)
(x0 − h − x0 )(x0 − h − (x0 + h))
(x − (x0 − h))(x − (x0 + h))
+f (x0 )
(x0 − (x0 − h))(x0 − (x0 + h))
(x − (x0 − h))(x − x0 )
+f (x0 + h)
(x0 + h − (x0 − h))(x0 + h − x0 )
(x − x0 )(x − x0 − h))
= f (x0 − h)
2h2
(x − x0 + h)(x − x0 − h)
+f (x0 )
−h2
(x − x0 + h)(x − x0 )
+f (x0 + h) .
2h2
Numerical Calculus I 12/21

Moreover,

p′2 (x) = f (x0 − h)


x − x0 − h + x − x0
2h2
x − x0 + h + x − x0 − h
+f (x0 )
−h2
x − x0 + h + x − x0
+f (x0 + h)
2h2
2x − 2x0 − h
= f (x0 − h)
2h2
2x − 2x0
+f (x0 )
−h2
2x − 2x0 + h
+f (x0 + h) .
2h2
Numerical Calculus I 13/21

So,

p′2 (x0 ) = f (x0 − h)


2x0 − 2x0 − h
2h2
2x0 − 2x0
+f (x0 )
−h2
2x0 − 2x0 + h
+f (x0 + h)
2h2
−h 0 h
= f (x0 − h) 2 + f (x0 ) 2 + f (x0 + h) 2
2h −h 2h
1
= (f (x0 + h) − f (x0 − h)).
2h
We have arrived at a central difference approximation to f ′ (x0 ),
1
(f (x0 + h) − f (x0 − h)).
2h
Numerical Calculus I 14/21

Furthermore,

p′′2 (x) = f (x0 − h)


2 2 2
+ f (x0 ) 2 + f (x0 + h) 2
2h2 −h 2h
1
= (f (x0 − h) − 2f (x0 ) + f (x0 + h)).
h2
So,
p′′2 (x0 ) =
1
(f (x0 − h) − 2f (x0 ) + f (x0 + h)).
h2
We have arrived at a central difference approximation to f ′′ (x0 ),
1
(f (x0 − h) − 2f (x0 ) + f (x0 + h)).
h2
Numerical Calculus I 15/21

Problem 3
Let f be given by f (x) = x − x2 − x3 .
Compute a central difference approximation to f ′ (0) using no more
of the values of f than f (−0.05) and f (0.05).
Compute a central difference approximation to f ′′ (0) using no more
of the values of f than f (−0.05), f (0) and f (0.05).
Compute the absolute error in the obtained approximation to f ′ (0).
Compute the absolute error in the obtained approximation to f ′′ (0).
Numerical Calculus I 16/21

We can compute that f (0) = 0, f (0.05) = 0.047375 and


f (−0.05) = −0.052375. A central difference approximation to f ′ (0) is
f (0.05) − f (−0.05) 0.09975
= = 0.9975.
0.1 0.1
A central difference approximation to f ′′ (0) is
f (−0.05) − 2f (0) + f (0.05) −0.005
= = −2.
0.052 0.0025
Now, f ′ (x) = 1 − 2x − 3x2 and so f ′ (0) = 1. Hence, the absolute error in
the obtained central difference approximation to f ′ (0) is

∣1 − 0.9975∣ = 0.0025.

Also, f ′′ (x) = −2 − 6x and so f ′′ (0) = −2. Hence, the absolute error in


the obtained central difference approximation to f ′′ (0) is

∣ − 2 − (−2)∣ = 0.
Numerical Calculus I 17/21

Problem 4
Suppose that a ∈ R, that b ∈ R and that a < b. Suppose that f ∈ C 3 [a, b],
that x0 ∈ (a, b) and that the positive number h is such that x0 − h ∈ [a, b)
and x0 + h ∈ (a, b].
Show that

∣f ′ (x0 ) − ∣f ′′′ (x)∣


f (x0 + h) − f (x0 − h)
∣ ≤ Chp max
2h x∈[x0 −h,x0 +h]

where C is a constant that you should determine and p is an integer


that you should determine.
Determine an integer m which is such that

f ′ (x0 ) −
f (x0 + h) − f (x0 − h)
= O(hm ).
2h
Numerical Calculus I 18/21

By Taylor’s Theorem, there exists ξ1 ∈ (x0 , x0 + h) for which

f (x0 + h) = f (x0 ) + f ′ (x0 )h + f ′′ (x0 )h2 + f ′′′ (ξ1 )h3


1 1
2 6
and there exists ξ2 ∈ (x0 − h, x0 ) for which

f (x0 − h) = f (x0 ) − f ′ (x0 )h + f ′′ (x0 )h2 − f ′′′ (ξ2 )h3 .


1 1
2 6
Hence,

h3 ′′′
f (x0 + h) − f (x0 − h) = 2hf ′ (x0 ) + (f (ξ1 ) + f ′′′ (ξ2 )) .
6
Consequently,

h2
f ′ (x0 ) − = − (f ′′′ (ξ1 ) + f ′′′ (ξ2 )) .
f (x0 + h) − f (x0 − h)
2h 12
Numerical Calculus I 19/21

Therefore,

∣f ′ (x0 ) −
f (x0 + h) − f (x0 − h)

2h
h2 ′′′
= ∣f (ξ1 ) + f ′′′ (ξ2 )∣
12
h2
≤ (∣f ′′′ (ξ1 )∣ + ∣f ′′′ (ξ2 )∣)
12
h2
≤ ( max ∣f ′′′ (x)∣ + max ∣f ′′′ (x)∣)
12 x∈[x0 ,x0 +h] x∈[x0 −h,x0 ]

h2
≤ ( max ∣f ′′′ (x)∣ + max ∣f ′′′ (x)∣)
12 x∈[x0 −h,x0 +h] x∈[x0 −h,x0 +h]

= Chp max ∣f ′′′ (x)∣


x∈[x0 −h,x0 +h]

1
where C = and p = 2.
6
Numerical Calculus I 20/21

Moreover,

h2
∣f ′ (x0 ) − ∣f ′′′ (x)∣
f (x0 + h) − f (x0 − h)
∣ ≤ max
2h 6 x∈[x0 −h,x0 +h]

h2
≤ max ∣f ′′′ (x)∣
6 x∈[a,b]
= αh2

where
max ∣f ′′′ (x)∣ .
1
α=
6 x∈[a,b]
Therefore,
f ′ (x0 ) −
f (x0 + h) − f (x0 − h)
= O(hm )
2h
where
m = 2.
Numerical Calculus I 21/21

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

You might also like