Taylor Series

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

TAYLOR SERIES AND POLYNOMIALS

• It’s like creating a recipe for the curve


Imagine you're trying to figure out how a curve behaves, like a based on:
roller coaster track, but you only know one point on the track. • 1. Where you are (the point on the
The Taylor series is like building a really good approximation of
the whole curve using just that one point and the information
curve).
about how steep the curve is at that point (its slope), how the • 2. How steep it is (first derivative).
steepness changes (curvature), and so on.
• 3. How quickly that steepness changes
(second derivative), and so on.

With each extra piece of information, you get a better and better idea of what the curve looks like near
that point. The more terms you add, the more accurate the approximation becomes.

In short, the Taylor series lets you approximate complex curves or functions using simpler terms—
essentially breaking down a complicated shape into small, easy-to-understand pieces, one step at a time.
It’s used in everything from computer graphics to engineering, where precise calculations are needed
but exact solutions are difficult.
APPLICATION IN CS
MATHEMATICAL REPRESENTATION

Taylor series and polynomials are of basic importance and used extensively in numerical
analysis, in approximating a differentiable function and its integral etc.

Taylor Series
Let f and its higher order derivatives be continuous on [a, b] and x0 be a fixed point in [a, b].
Then, for x ∈ [a, b], 𝑓(𝑥) can be expressed as the infinite series (called Taylor’s Series)
𝑓 ′′ (𝑥0 ) 𝑓 (𝑛) (𝑥0 ) 𝑓 (𝑛+1) (𝑥0 )
𝑓(𝑥) = 𝑓(𝑥0 ) + 𝑓 ′ (𝑥0 )(𝑥 − 𝑥0 ) + 2
(𝑥 − 𝑥0 ) + ⋯ + 𝑛
(𝑥 − 𝑥0 ) + (𝑥 − 𝑥0 )𝑛+1 + ⋯
2! 𝑛! (𝑛 + 1)!

Taylor Polynomial
𝑓(𝑛) (𝑥0 )
If the Taylor’s series is truncated to the term (𝑥 − 𝑥0 )𝑛 , then the polynomial
𝑛!
obtained is called the Taylor’s polynomial
′′ 𝑛 ( )
′ 𝑓 (𝑥0 ) 2 𝑓 (𝑥0 )
𝑓(𝑥) ≈ 𝑃𝑛 (𝑥) = 𝑓(𝑥0 ) + 𝑓 (𝑥0 )(𝑥 − 𝑥0 ) + (𝑥 − 𝑥0 ) + ⋯ + (𝑥 − 𝑥0 )𝑛
2! 𝑛!
Theorem (Taylor’s Theorem)
Suppose f ∈ Cn [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
𝑓(𝑥) = 𝑃𝑛 (𝑥) + 𝑅𝑛 (𝑥)
Where

′(
𝑓 ′′ (𝑥0 ) 2
𝑓 (𝑛) (𝑥0 )
𝑃𝑛 (𝑥) = 𝑓 (𝑥0 ) + 𝑓 𝑥0 )(𝑥 − 𝑥0 ) + (𝑥 − 𝑥0 ) + ⋯ + (𝑥 − 𝑥0 )𝑛
2! 𝑛!
and
𝑓 (𝑛+1) (𝜉(𝑥))
𝑅𝑛 (𝑥) = (𝑥 − 𝑥0 )𝑛+1 .
(𝑛 + 1)!
Here 𝑃𝑛 (𝑥) is the nth Taylor polynomial for f about x0, and 𝑅𝑛 (𝑥) is the remainder term (or
truncation error) associated with 𝑃𝑛 (𝑥). Since the number ξ(x) in the truncation error 𝑅𝑛 (𝑥)
depends on the value of x at which the polynomial 𝑃𝑛 (𝑥) is being evaluated, it is a function of
the variable x. However, we should not expect to be able to explicitly determine the function
ξ(x). Taylor’s Theorem simply ensures that such a function exists, and that its value lies
between x and 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.
The term truncation error in the Taylor polynomial refers to the error involved in using a
truncated, or finite, summation to approximate the sum of an infinite series.
GRAPHICAL REPRESENTATION

EXAMPLES

Example 1. Let f (x) = cos x and x0 = 0. Determine


(a) the second, third and fourth Taylor polynomial for f about x0; and use these polynomials
to approximate f (0.02) by finding the actual error.
(b) an upper bound for |f (0.02) − 𝑃𝑛 (0.02)| using the error formula 𝑅2 (𝑥), compare it to the
actual error.
Solution. Since f ∈ C∞(R), Taylor’s Theorem can be applied for any n ≥ 0. Also,
𝑓 ′ (𝑥) = − sin 𝑥 , 𝑓 ′′ (𝑥) = − cos 𝑥 , 𝑓 ′′′ (𝑥) = sin 𝑥 , and 𝑓 (4) (𝑥) = cos 𝑥,
So
𝑓 (0) = 1, 𝑓 ′ (0) = 0, 𝑓 ′′ (0) = −1, 𝑓 ′′′ (0) = 0, 𝑎𝑛𝑑 𝑓 (4) (0) = 1.

(a) For n = 2 and 𝑥0 = 0, we have



𝑓′′ (0) 1 2
𝑃2 (𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 𝑥2 = 1 − 𝑥
2! 2
To approximate f (0.02),
we use 𝑃2 (𝑥) at x = 0.02,
Implies 𝑃2 (0.02) =0.9998

While exact value is

cos 0.02 = 0.9998000067,

Therefore, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫


= 6.67 × 10−9 .
For n = 3 and 𝑥0 = 0, we have

𝑓′′ (0) 𝑓′′′ (0) 1 2
𝑃3 (𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 2
𝑥 + 𝑥3 = 1 − 𝑥
2! 3! 2
𝑃3 (0.02) =0.9998, same as 𝑃2 (0.02).
For n = 4 and 𝑥0 = 0, we have
𝑓′′ (0) 𝑓′′′(0) 𝑓(4) (0)
𝑃4 (𝑥) = 𝑓(0) + 𝑓 ′ (0)𝑥 + 𝑥2 + 𝑥3 + 𝑥4
2! 3! 4!
1 1
= 1 − 𝑥2 + 𝑥4
2! 4!

⟹ 𝑃4 (0.02) =0.99980001

(b) To find upper bound of error we use formula


𝑓 (𝑛+1) (𝜉(𝑥))
𝑅𝑛 (𝑥) = (𝑥 − 𝑥0 )𝑛+1 .
(𝑛 + 1)!
where ξ(x) is some (generally unknown) number between 0 and x.
Therefore, the upper bound of error for 𝑃2 (𝑥) will be
𝑓 ′′′ (𝜉 (𝑥)) 3 sin 𝜉 (𝑥) 3
𝑅2 (𝑥) = 𝑥 = 𝑥
3! 6
The error bound is much larger than the actual error. This is due to the poor bound we used
for | sin ξ(x)|.
As from calculus, we have | sin x| ≤ |x|. Since 0 ≤ ξ < 0.02, we could have used the fact that
| sin ξ(x)| ≤ 0.02 in the error formula, producing the bound 𝑅2 (0.02) =2.67 × 10−8.
Similarly, the upper bound of error for 𝑃3 (𝑥) will be
𝑓 (4) (𝜉(𝑥)) 4 cos 𝜉 (𝑥) 4
𝑅3 (𝑥) = 𝑥 = 𝑥
4! 24
Since, | cos ξ(x)| ≤ 1, so 𝑅3 (0.02) ≤ 6.67 × 10−9 .

Example 2.
Find Taylor series and polynomials of degree 4 and 5 for the function sin 𝑥 about 𝑥0 = 0 and
use the polynomial to find the actual error at 𝑥 = 0.1 and 𝑥 = 0.5.
Solution: 𝑓(𝑥) = sin 𝑥 , 𝑓(0) = 0
′ (𝑥)
𝑓 = cos 𝑥, 𝑓 ′ ( 0) = 1
𝑓 ′′ (𝑥) = − sin 𝑥, 𝑓 ′′ (0) = 0
𝑓 ′′′ (𝑥) = − cos 𝑥, 𝑓 ′′′ (0) = −1
𝑓 (4) (𝑥) = sin 𝑥, 𝑓 (4) (0) = 0


𝑓′′ (0) 𝑓′′′ (0) 𝑓(4) (0)
𝑓(𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 𝑥 + 2 3
𝑥 ++ 𝑥4 + ⋯
2! 3! 4!
𝑥3 𝑥5 𝑥7
sin 𝑥 = 𝑥 − + − +⋯
3! 5! 7!
𝑥3 𝑥3 𝑥5
or sin 𝑥 ≈ 𝑃4 (𝑥) = 𝑥 − and sin 𝑥 ≈ 𝑃5 (𝑥) = 𝑥 − +
3! 3! 5!

To approximate f (0.05) at 𝑥 = 0.1, we use 𝑃4 (𝑥) and 𝑃5 (𝑥) at x = 0.1, respectively


Implies 𝑃4 (0.1) =0.09983333 and 𝑃5 (0.1) = 0.09983341667.

While exact value is sin 0.1 = 0.09983341665,

Therefore, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 for 𝑃4 (0.1) = 8.7 × 10−8 and for 𝑃5 (0.1) = 2 × 10−11 , resp.
* But if we check error at 𝑥 = 0.5, with 𝑃5 (0.5) = 0.4794271
and exact value is sin 0.5 = 0.4794255,

Therefore, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 = 0.0000016, greater error at point farther from 𝑥0 = 0.

Example 3. Find 𝑃2 (𝑥) for the function 𝑓(𝑥) = 𝑒 𝑥 cos 𝑥 about x0 = 0.


(a) Use 𝑃2 (0.5) to approximate f (0.5) by finding the actual error.
(b) Find an upper bound of error |𝑓 (0.5) − 𝑃2 (0.5)| using formula 𝑅2 (𝑥), and compare
it to the actual error.
(c) Find an upper bound of error |𝑓 (𝑥) − 𝑃2 (𝑥)| using 𝑅2 (𝑥) on the interval [0,1].
1 1
(d) Approximate ∫0 𝑓(𝑥)𝑑𝑥 using ∫0 𝑃2 (𝑥) 𝑑𝑥 .
Solution. As, 𝑓(𝑥) = 𝑒 𝑥 cos 𝑥,
so 𝑓 ′ (𝑥) = 𝑒 𝑥 (cos 𝑥 − sin 𝑥), 𝑓 ′′ (𝑥) = −2𝑒 𝑥 sin 𝑥,
and 𝑓 ′′′ (𝑥) = −2𝑒 𝑥 (cos 𝑥 + sin 𝑥)
So
𝑓 (0) = 1, 𝑓 ′ (0) = 1, 𝑓 ′′ (0) = 0.
For n = 2 and 𝑥0 = 0, we have

𝑓′′ (0)
𝑃2 (𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 𝑥2 = 1 + 𝑥
2!
(a) 𝑃2 (0.5) = 1.5
While exact value is 𝑓(0.5) = 1.4469 So, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 = 0.0531.

(b) To find upper bound of error for 𝑃2 (𝑥) will be


𝑓 ′′′ (𝜉 (𝑥)) 3 𝑥 3 𝜉(𝑥)
𝑅2 (𝑥) = 𝑥 =− 𝑒 (cos 𝜉 (𝑥) + sin 𝜉 (𝑥))
3! 3
0.53
so |𝑅2 (0.5)| = |− | |𝑒𝜉(𝑥) (cos 𝜉(𝑥) + sin 𝜉(𝑥))|
3

≤ 0.103 taking 𝜉 (𝑥) = 0.5, cos 𝜉 (𝑥) = 1 and sin 𝜉 (𝑥) = 𝜉 (𝑥) .

(c) To find upper bound of error for 𝑃2 (𝑥) on the interval [0,1]

𝑓 ′′′ (𝜉 (𝑥)) 3 𝑥 3 𝜉(𝑥)


𝑅2 (𝑥) = 𝑥 =− 𝑒 (cos 𝜉 (𝑥) + sin 𝜉 (𝑥))
3! 3
13 𝜉(𝑥)
≤ |− | |𝑒 (cos 𝜉 (𝑥) + sin 𝜉 (𝑥))|
3

= 1.812 taking 𝜉(𝑥) = 1, cos 𝜉 (𝑥) = 1, sin 𝜉 (𝑥) = 𝜉 (𝑥)


1
(d) To approximate ∫0 𝑓(𝑥)𝑑𝑥 , we use

1 1
∫0 𝑃2 (𝑥) 𝑑𝑥 = ∫0 (1 + 𝑥) 𝑑𝑥 = 1.5
1
While exact value is ∫0 𝑒 𝑥 cos 𝑥 𝑑𝑥 = 1.378.

Example 4. Let 𝑓(𝑥) = √1 − 𝑥 and x0 = 0. Determine


(a) Third and fourth Taylor polynomial for f about x0; and use these polynomials to
approximate f (0.2) by finding the actual error.
(b) an upper bound of error using formula 𝑅3 (𝑥), compare it to the actual error.
0.5 0.5
(c) Approximate ∫0 𝑓(𝑥)𝑑𝑥 using ∫0 𝑃3 (𝑥) 𝑑𝑥 .
Solution. As, 𝑓(𝑥) = √1 − 𝑥,
1 1 1 3
so 𝑓 ′ (𝑥) = − 2 (1 − 𝑥)−2 , 𝑓 ′′ (𝑥) = − (1 − 𝑥)−2 ,
4
3 15
𝑓 ′′′ (𝑥) = − (1 − 𝑥)−5/2 , and 𝑓 (4) (𝑥) = − (1 − 𝑥)−7/2
8 16
So
1 1
𝑓 (0) = 1, 𝑓 ′ (0 ) = − , 𝑓 ′′ (0) = − ,
2 4
3 15
𝑓 ′′′ (0) = − , 𝑎𝑛𝑑 𝑓 (4) (0) = − .
8 16

(a) For n = 3 and 𝑥0 = 0, we have



𝑓′′ (0) 𝑓′′′ (0)
𝑃3 (𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 2
𝑥 + 𝑥3
2! 3!
1 1 1
= 1 − 𝑥 − 𝑥2 − 𝑥3
2 8 16

𝑃3 (0.2) = 0.8945
While exact value is 𝑓(0.2) = √1 − 0.2 = 0.8944272
So, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 = 7 × 10−5 .
For n = 4 and 𝑥0 = 0, we have

𝑓′′ (0) 𝑓′′′ (0) 𝑓(4) (0)
𝑃4 (𝑥) = 𝑓(0) + 𝑓 (0)𝑥 + 𝑥 + 2 3
𝑥 + 𝑥4
2! 3! 4!
1 1 1 5
= 1 − 𝑥 − 𝑥2 − 𝑥3 − 𝑥4
2 8 16 128

⟹ 𝑃4 (0.2) = 0.8944375.
Therefore, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 = 1.03 × 10−5 .
(b) To find upper bound of error for 𝑃3 (𝑥) will be
𝑓 (4) (𝜉 (𝑥)) 4 5
𝑅3 (𝑥) = 𝑥 =− (1 − 𝜉 (𝑥))−7/2 𝑥 4
4! 128
so 𝑅3 (0.2) ≤ 1.365 × 10−4 taking 𝜉(𝑥) = 0.2.
0.5
(c) To approximate ∫0 𝑓(𝑥)𝑑𝑥 , we use

0.5 0.5 1 1 1
∫0 𝑃3 (𝑥) 𝑑𝑥 = ∫0 (1 − 2 𝑥 − 8 𝑥 2 − 16 𝑥 3 ) 𝑑𝑥 = 0.431315
0.5
While exact value is ∫0 √1 − 𝑥 𝑑𝑥 = 0.430964.
Therefore, 𝐀𝐜𝐭𝐮𝐚𝐥 𝐞𝐫𝐫𝐨𝐫 = 3.51 × 10−4 .

PROBLEM STATEMENT
ANSWERS
(Solve it yourself!)

Function value at x = 0.5 : 1.4468890365841693


Taylor polynomial approximation at x = 0.5 : 1.4270833333333333
Actual error at x = 0.5: 0.019805703250836082
Upper bound of truncation error at x = 0.5: 0.0008547525434512426

ERROR ANALYSIS
PYTHON CODE

You might also like