Jan 2016
Introduction
The main problem of computational calculus is to compute derivatives
and integrals. There are two directions that we can take for such
problems, numerical computing and symbolic computing. Both
derivatives and integrals have clear definitions, but the type of answer
wanted by a user often depends on the way in which the functions is
specified.
In practice, ther are two other ways for a function to be known. A
function may be specified as a tabulated list, for example, a collection
of time/temperature pairs measured from an experiment, perhaps at
evenly spaced times. In this case, finding the derivative or
anti-derivative from the rules of freshman calculus is impossible.
Finally, a function may be specified as the output of an experiment or
computer simulation whose input is specified by the user. In the latter
two cases, symbolic computing methods cannot be applied, and
numerical differentiation and integration are required to solve the
problems.
By Ng Tin Yau (PhD) 2/18
Differentiability
Let f be a function defined on a set X of real numbers and x0 X.
Then f is continuous at x0 if
lim f (x) = f (x0 )
xx0
xx0
f (x) f (x0 )
x x0
(1)
Taylors Theorem
Suppose f C n [a, b], that f (n+1) exists on [a, b] and x0 [a, b]. For
every x [a, b], there exists a number (x) between x0 and x with
f (x) = Pn (x) + Rn (x), where
Pn (x) =
n
X
f (k) (x0 )
k=0
and
Rn (x) =
k!
(x x0 )k
f (n+1) ((x))
(x x0 )n+1
(n + 1)!
(2)
(3)
Here Pn (x) is called the n-th Taylor polynomial for f about x0 , and
Rn (x) is called the remainder term associated with Pn (x).
The infinite series obtained by taking the limit of Pn (x) as n is
called the Taylor series for f about x0 . In the case x0 = 0, the Taylor
polynomial is often called a Maclaurin polynomial, and the Taylor
series is often called a Maclaurin series.
By Ng Tin Yau (PhD) 4/18
Example 1
f 00 (x) = cos x
so
f (0) = 1 f 0 (0) = 0 f 00 (0) = 1
f (3) (0) = 0
Example 1a
For n = 2 and x0 = 0, we have
x2 00
x3
f (0) + f (3) ((x))
2!
3!
1 2 1 3
= 1 x + x sin (x)
2
6
106
sin (0.01)
6
Example 1b
For n = 3 and x0 = 0, we have
1
1
cos x = 1 x2 + x4 cos (x)
2
24
where 0 < (x) < 0.01. When x = 0.01, the error term
1
(0.01)4 cos (0.01) 1 (0.01)4 4.2 1010
24
24
The approximation to cos 0.01 given by the Taylor polynomial is still
0.99995. However, the error bound is given by
| cos 0.01 0.99995| 4.2 1010
Remarks: This example illustrates the two objectives of numerical
analysis:
1. Find an approximation to the solution of a given problem.
2. Determine a bound for the accuracy of the approximation.
By Ng Tin Yau (PhD) 7/18
An Alternative Form
If we set x 7 x0 + h in the Taylors series, then
f (x0 + h) =
f 0 (x0 ) = lim
h3 (3)
f (x0 ) +
3!
h3 (3)
f (x0 ) +
3!
(4)
(5)
f (x0 + h) f (x0 ) h 00
f ()
h
2
(6)
For small values of h, the difference quotient [f (x0 + h) f (x0 )]/h can
be used to approximate f 0 (x0 ) with an error bounded by M |h|/2 where
M is a bound on |f 00 (x)| for x (x0 , x0 + h). The formula is known as
the forward-difference formula and in the case where h < 0, it is
called the backward-difference formula.
By Ng Tin Yau (PhD) 9/18
Example 2
Use the forward-difference formula to approximate the derivative of
f (x) = ln x at x0 = 1.8 using h = 0.1 and determine bounds for the
approximation errors.
Solution: For h = 0.1, the forward-difference formula gives
f 0 (1.8)
0.64185389 0.58778667
ln 1.9 ln 1.8
=
= 0.5406722
0.1
0.1
Because f 00 (x) = 1/x2 and 1.8 < < 1.9, a bound for this
approximation error is
|h|
|hf 00 ()|
0.1
= 2 <
= 0.0154321
2
2
2(1.8)2
In
On the other hand, f 0 (x) = 1/x and the exact value of f 0 (1.8) is 0.5.
this case the error bounds are quite close to the true approximation
error.
By Ng Tin Yau (PhD) 10/18
4h3 (3)
f ()
3!
h2
1
[3f (x0 ) + 4f (x0 + h) f (x0 + 2h)] + f (3) ()
2h
3
(7)
1
h2
[f (x0 + h) f (x0 h)] f (3) ()
2h
6
(8)
Discussions
Although the errors in both 3-point formulas are O(h2 ), the error in
the midpoint formula is approximately half the error in the endpoint
formula. However, the approximation in the endpoint formula is useful
near the ends of an interval, because information about f outside the
interval may not be available.
5-point Formulas
It is possible to obtain 5-point formulas that involve evaluating the
function at two additional points. The error term for these formulas is
O(h4 ). Common 5-point formulas include the 5-point midpoint
formula:
h4
1
[f (x0 2h)8f (x0 h)+8f (x0 +h)f (x0 +2h)]+ f (5) ()
2h
30
(9)
and the 5-point endpoint formula:
f 0 (x0 ) =
f 0 (x0 ) =
1
[25f (x0 ) + 48f (x0 + h) 36f (x0 + 2h)
2h
h4
+16f (x0 + 3h) 3f (x0 + 4h)] + f (5) ()
5
(10)
h2 (4)
1
[f
(x
h)
2f
(x
)
+
f
(x
+
h)]
f ()
0
0
0
h2
12
(11)
Example 3
Given f (x) = xex and using h = 0.1, estimate f 0 (2.0) and f 00 (2.0) using
the first and second derivative midpoint formulas, respectively.
Solution: Using the function f , we generate the following data:
x
f (x)
1.9
12.703199
2.0
14.778112
2.1
17.148957
f (2.1) f (1.9)
= 5(17.148957 12.7703199) = 22.228790
2(0.1)
Example 4
Use
0.1 the third Taylor polynomial and its reminder term to approximate
0 cos xdx.
Solution: Recall that
1
1
cos x = 1 x2 + x4 cos (x)
2
24
Now
0.1
Therefore,
0.1
cos xdx
0
0.1
1
1
1 x2 dx +
x4 cos (x)dx
2
24 0
0.1
cos xdx =
0.1
1 2
1
1 x dx = 0.1 (0.1)3 = 0.09983
2
6
Example 4 cont
A bound for the error in this approximation is determined from the
integral of the Taylor remainder term and the fact that | cos (x)| 1
for all x:
0.1
1
1 0.1 4
x cos (x)dx
x4 | cos (x)|dx
24 0
24 0
0.1
1
0.15
x4 dx =
= 8.
3 108
24 0
120
The true value of this integral is
0.1
cos xdx = sin 0.1 0.099833416647
0
Exercises
(1) Find the second Taylor polynomial P2 (x) for the function
f (x) = ex cos x about x0 = 0.
a. Use P2 (0.5) to approximate f (0.5). Find an upper bound for error
|f (0.5) P2 (0.5)| using the error formula, and compare it to the
actual error.
b. Find a bound for the error |f (x) P2 (x)| in using P2 (x) to
approximate f (x) on the interval [0, 1].
(2) Let f (x) = 3xex cos x. Using the following data
x
f (x)
1.20
11.59006
1.29
13.78176
1.30
14.04276
1.31
14.30741
1.40
16.86187