Document

advertisement
Taylor Series Revisited
http://numericalmethods.eng.usf.edu
What is a Taylor series?
Some examples of Taylor series which you must have
seen
x2 x4 x6
cos( x) = 1 − +
− +L
2! 4! 6!
x3 x5 x7
sin( x) = x − + − + L
3! 5! 7!
x2 x3
e = 1+ x +
+
+L
2! 3!
x
2
http://numericalmethods.eng.usf.edu
General Taylor Series
The general form of the Taylor series is given by
f ′′( x ) 2 f ′′′( x ) 3
f ( x + h ) = f ( x ) + f ′( x )h +
h +
h +L
2!
3!
provided that all derivatives of f(x) are continuous and
exist in the interval [x,x+h]
What does this mean in plain English?
As Archimedes would have said, “Give me the value of the function
at a single point, and the value of all (first, second, and so on) its
derivatives at that single point, and I can give you the value of the
function at any other point” (fine print excluded)
3
http://numericalmethods.eng.usf.edu
Example—Taylor Series
Find the value of f (6) given that f (4) = 125, f ′(4) = 74,
f ′′(4) = 30, f ′′′(4) = 6 and all other higher order derivatives
of f (x ) at x = 4 are zero.
Solution:
h2
h3
f (x + h ) = f (x ) + f ′(x )h + f ′′(x ) + f ′′′(x ) + L
2!
3!
x=4
h = 6−4 = 2
4
http://numericalmethods.eng.usf.edu
Example (cont.)
Solution: (cont.)
Since the higher order derivatives are zero,
22
23
f (4 + 2) = f (4) + f ′(4)2 + f ′′(4) + f ′′′(4)
2!
3!
 2 2   23 
f (6) = 125 + 74(2) + 30  + 6 
 2!   3! 
= 125 + 148 + 60 + 8
= 341
Note that to find f (6) exactly, we only need the value
of the function and all its derivatives at some other
point, in this case x = 4
5
http://numericalmethods.eng.usf.edu
Error in Taylor Series
The Taylor polynomial of order n of a function f(x)
with (n+1) continuous derivatives in the domain
[x,x+h] is given by
h2
hn
(n )
f ( x + h ) = f (x ) + f ′(x )h + f ' ' ( x ) + L + f ( x ) + Rn ( x )
2!
n!
where the remainder is given by
n +1
(
x − h)
R (x )
f (n +1) (c )
n
=
( n + 1)!
where
x < c < x+h
that is, c is some point in the domain [x,x+h]
6
http://numericalmethods.eng.usf.edu
Example—error in Taylor series
x
The Taylor series for e at point x = 0 is given by
x 2 x3 x4 x5
e =1+ x +
+ +
+ +L
2! 3! 4! 5!
x
It can be seen that as the number of terms used
increases, the error bound decreases and hence a
better estimate of the function can be found.
How many terms would it require to get an
approximation of e1 within a magnitude of
true error of less than 10-6.
7
http://numericalmethods.eng.usf.edu
Example—(cont.)
Solution:
Using (n + 1) terms of Taylor series gives error bound of
n +1
(
x − h)
x = 0, h = 1, f ( x ) = e x
f (n +1) (c )
Rn ( x ) =
(n + 1)!
n +1
(
0 − 1)
Rn (0 ) =
f (n +1) (c )
(n + 1)!
n +1
(
− 1)
=
ec
(n + 1)!
Since
x < c < x+h
0 < c < 0 +1
0 < c <1
8
1
e
< Rn (0 ) <
(n + 1)!
(n + 1)!
http://numericalmethods.eng.usf.edu
Example—(cont.)
Solution: (cont.)
So if we want to find out how many terms it would
1
require to get an approximation of e within a
magnitude of true error of less than 10 −6 ,
e
< 10 − 6
( n + 1)!
(n + 1)!> 10 6 e
(n + 1)!> 10 6 × 3
n≥9
So 9 terms or more are needed to get a true error
less than 10 −6
9
http://numericalmethods.eng.usf.edu
Example: Evaluate the following function at x=1.0002
using Maple 10-digit floating point arithmetic
Naïve calculation:
Find the Taylor polynomial of f(1+h) of degree 3:
10
http://numericalmethods.eng.usf.edu
The remainder, for c between 1 and 1.0002
So the value is approximately 0.33330247
Confimation using 30-digit evaluation
11
http://numericalmethods.eng.usf.edu
Homework:
1. For the function
(i)
(ii)
(iii)
(iv)
(v)
(vi)
Evaluate f(2.01) directly in Maple
Find the Taylor polynomial of f(2+h) of degree 5
Evaluate f(2.01) using the Taylor polynomial in (ii)
Find the remainder
Plot the remainder and estimate the error of Taylor polynomial
Evaluate f(2.01) using 30-digit evaluation to confirm
the value and error
2. For a function f(x), we know
f(2.3) = 1.54, f’(2.3) = -3.21, f’’(2.3) = 0, f’’’(2.3) = 6.11
what are the values of f(2.3105) and f(2.2993) approximately?
3. How to calculate f(0.524) for f(x) =
accurately using 10-digit, knowing
12
http://numericalmethods.eng.usf.edu
Evaluate the function value
for the following function
(1)
Direct naive evaluation:
0.40
compare with the 30-digit evaluation:
0.3333024733018875360460
(2)
(3)
Why is the direct calculation wrong?
0.6666666667
(4)
1.791792802
(5)
1.791726135
(6)
0.6667333300
(7)
0.666733334
(8)
(9)
Information in the first 8 or 9 digits is lost by the final subtraction (of near identical number)
A classical example: To solve
,
How about:
(10)
The first root 0 is clearly wrong. The correct 1st root should be
(11)
Example : Evaluate f(1.997) of the function
(12)
Direct evaluation:
1.126000
(13)
1.02079836969567275733483
(14)
In 30-digit evaluation:
Using Taylor's polynomial:
(15)
1.020796875
(16)
c
(17)
The remainder:
(18)
The error is at the 6-th digits after the decimal point. So the Taylor polynomial evaluation is correct for
6 digits: 1.02079
Download