Lecture 3
Taylor Series Expansion
Taylor series, is of great value in the study of numerical methods. This series provides
a means to predict a function value at one point in terms of the function value and its
derivatives at another point. In particular, the theorem states that any smooth function can
be approximated as a polynomial. If a function f and its first n + 1 derivatives are continuous
on an interval containing a and x, then the value of the function at x is given by
′′
′
f (x) = f (a) + f (a)(x − a) +
=
k=n
∑
k=0
f (k) (a)
′′′
f (a)
f (a)
f n (a)
(x − a)2 +
(x − a)3 + · · · +
(x − a)n + Rn
2!
3!
n!
(x − a)k
+ Rn
k!
where the Reminder Rn is defined as:
∫
Rn =
|
a
x
(x − t)n n+1
f (n+1) f (ξ)
f (t)dt =
(x − a)n+1
2!
(n + 1)!
{z
} |
{z
}
Integral f orm
(3.1)
derivative f orm
where t is a dummy variable and ξ is a value between x and a. Maclaurin series
Maclaurin series is a special case of Taylor series with the center of expansion a = 0. Maclau-
11
rin series expansion of f (x) is
′′
′′′
f (0) 2 f (0) 3
f n (0) n
f (x) = f (0) + f (0)(x) +
(x) +
(x) + · · · +
(x) + Rn
2!
3!
n!
k=n
∑
(x)k
=
f (k) (0)
+ Rn
k!
k=0
′
Example 1
Use zero- through fourth-order Taylor series expansions to ap-
proximate the function
f (x) = −0.1x4 − 0.15x3 − 0.5x2 − 0.25x + 1.2
from xi = 0 with h = 1. That is, predict the functions value at xi + 1 = 1.
Solution
Because we are dealing with a known function, we can compute values for f (x)
between 0 and 1. f (0) = 1.2 and then curves downward to f (1) = 0.2. Thus, the
true value that we are trying to predict is 0.2.
The Taylor series approximation with n = 0 is
f (xi+1 ) ≃ 1.2
ϵt = 0.2 − 1.2 = −1.0
For n = 1, the first derivative must be determined and evaluated at x = 0:
f ′ (0) = −0.4(0.0)3 − 0.45(0.0)2 − 1.0(0.0) − 0.25 = −0.25
Fall 2014, Group A
12
The first-order approximation is
f (xi+1 ) ≃ 1.2 − 0.25h
which can be used to compute f (1) = 0.95. The approximation begins to be
closer to the true value.
This results in a reduction of the truncation error to
ϵt = 0.2 − 0.95 = −0.75
For n = 2, the second derivative is evaluated at x = 0:
f ′′ (0) = −1.2(0.0)2 − 0.9(0.0) − 1.0 = −1.0
∴
f (xi+1 ) ≃ 1.2 − 0.25h − 0.5h2
and substituting h = 1, f (1) = 0.45. Note that the second derivative improves
the estimation. Error is reduced further to 0.2 − 0.45 = −0.25. Additional terms
would improve the approximation even more. In fact, the inclusion of the third
and the fourth derivatives results in exactly the same equation we started with:
f (x) = 1.2 − 0.25h − 0.5h2 − 0.15h3 − 0.1h4
where the remainder term is
R4 =
f (5) (ζ)h5
=0
5!
The Taylor series expansion to the fourth derivative yields an exact estimate at
xi+1 = 1:
f (1) = 1.2 − 0.25(1) − 0.5(1)2 − 0.15(1)3 − 0.1(1)4 = 0.2
Fall 2014, Group A
13
Example 2
How many terms it would require to get an approximation of e1
within magnitude of true error of less than 10−6 .
Solution
Using Equation 3.1,
Rn (x + h) =
x = 0,
Rn (1) =
hn+1 (n+1)(ζ)
f
(n + 1)!
h = 1,
f (x) = ex
1n+1 (n+1)(ζ)
1
f
=
eζ
(n + 1)!
(n + 1)!
x <ζ <x+h
⇒
0 <ζ <1
1
e
<| Rn (1) |<
(n + 1)!
(n + 1)!
Since we may estimate e1 is not greater than 3;
(n + 1)! > 3 × 106
8! = 40320,
10! = 3.6288 × 106 . So n = 9 gives estimation
9! = 362880,
for e1 with an error less than 10−6 .
In general we can summarize: To know the number of terms needed for Taylor series to get
an error less than εs is given by:
M (x − x0 )n+1
≤ εs ,
(n + 1)!
where M is the largest value of the derivative of the function. The above inequality can be
solved using trial and error method.
Example 3
What is the required number of terms in Taylor series to evaluate
sin(π/2) with error less than 0.0001?.
Fall 2014, Group A
14
Solution
x0 = 0
and
M =1
(π/2 − 0)n+1
≤ 0.0001
(n + 1)!
Solving this inequality leads to n = 9.
Example 4
• Obtain the Maclaurin expansion for the following functions:
– f1 (x) = ex
– f2 (x) = sin(x)
– f3 (x) = cos(x)
– f4 (x) =
1
1−x
• Obtain the taylor expansion for the following functions:
– g1 (x) =
1
x
at a = 1.
– g2 (x) = ln(x) at a = 1.
Convergence of Taylor Series
The Taylor series converges fast (few terms are needed) when x is near the point of expansion.
If |x − a| is large then more terms are needed to get a good approximation.
Error Propagation
Errors can propagate through mathematical functions. For example, if we multiply two
numbers that have errors, we would like to estimate the error in the product. suppose we
Fall 2014, Group A
15
have a function f (x) and the variable x has some error. Assume that x̂ is an approximation
of x.
∆(x̂) =| f (x) − f (x̂) |
To illustrate this problem, let us take this simple example:
Given x̂ = 2.5 with an error ∆X̂ = 0.01. Estimate the resulting error in the function
f (x) = x3 . Taylor series can be used to compute f (x) near f (x̂) (assuming continuity and
differentiability at x̂). So the error can be estimated as
′′
f (x̂)
f (x) = f (x̂) + f (x̂)(x − x̂) +
(x − x̂)2 + · · ·
2!
′
By droping the second and higher order terms, we get
′
f (x) − f (x̂) = f (x̂)(x − x̂)
′
∆(x̂) =| f (x̂) | ∆x̂
Using this
∆f (x̂) ≃ 3(2.5)2 (0.01) = 0.1875
because f (2.5) = 15.625, we predict that
f (2.5) = 15.625 ± 0.1875,
or that the true value lies between 15.4375 and 15.8125.
Taylor series in Matlab
There are useful commands and function in Matlab that allow you to solve any function and
track the results in graphs.
Fall 2014, Group A
16
• taylor(f )
taylor(f,Name,Value)
taylor(f,v)
taylor(f,v,Name,Value)
taylor(f,v,a)
taylor(f,v,a,Name,Value)
Review Online matlab Help for details Sample examples:
syms x
taylor(exp(x))
taylor(sin(x))
taylor(cos(x))
ans =
x5 /120 + x4 /24 + x3 /6 + x2 /2 + x + 1
ans =
x5 /120 − x3 /6 + x
ans =
x4 /24 − x2 /2 + 10
t1 = taylor(f, ’Order’, 8)
t1 =
−x6 /5040 + x4 /120 − x2 /6 + 1
• taylortool
taylortool initiates a GU I that graphs a function against the N th partial sum of its
Fall 2014, Group A
17
Taylor series about a base point x = a.
Try to type the follwoing command:
taylortool (’sin(tan(x)) - tan(sin(x))’)
Fall 2014, Group A
18
© Copyright 2026 Paperzz