Numerical Methods - Mclaurin Series
Numerical Methods - Mclaurin Series
1. Determine machine epsilon in both double and single precision for Excel Visual
Basic.
SOLUTION:
Option Explicit
Function MachEps()
Dim eps As Single, eps1 As Single, eps2 As Single
eps = 1
Do
eps1 = 1 + eps
eps2 = eps1 - 1
If (eps2 <= 0) Then
Exit Do
End If
eps = eps / 2
Loop
MachEps = eps
End Function
MachEps = 5.96046E-08
Option Explicit
Function MachEps()
Dim eps As Double, eps1 As Double, eps2 As Double
eps = 1
Do
eps1 = 1 + eps
eps2 = eps1 - 1
If (eps2 <= 0) Then
Exit Do
End If
eps = eps / 2
Loop
MachEps = eps
End Function
MachEps = 1.11022E-16
x 2 x 4 x6 x8
cos x = 1 − + − + −"
2 4! 6! 8!
Starting with the simplest version, cosx=1, add terms one at a time to estimate
cos(π/4). After each new term is added, compute the true and approximate percent
relative errors. Use your pocket calculator to determine the true value. Add terms until
the absolute value of the approximate error estimate falls below an error criterion
conforming to two significant figures.
SOLUTION:
ε s = (0.5 × 10 2− n )%
Zero order:
⎛π ⎞
cos⎜ ⎟ ≈ 1 ;
⎝4⎠
⎛π ⎞
True value is cos⎜ ⎟ = 0.707107 ;
⎝4⎠
0.707107 − 1
εt = × 100% = −41.42%
0.707107
First order:
⎛π ⎞
cos⎜ ⎟ = 1 −
(π / 4) = 0.691575 ;
2
⎝4⎠ 2
0.707107 − 0.691575
εt = × 100% = −2.19% ;
0.707107
0.691575 − 1
εa = × 100% = −44.6%
0.691575
Second order:
⎛π ⎞
cos⎜ ⎟ = 1 −
(π / 4) + (π / 4) = 0.707429 ;
2 4
⎝4⎠ 2 4!
0.707107 − 0.707429
εt = × 100% = −0.455% ;
0.707107
0.707429 − 0.691575
εa = × 100% = 2.24%
0.707429
Third order:
⎛π ⎞
cos⎜ ⎟ = 1 −
(π / 4) + (π / 4) − (π / 4) = 0.707103 ;
2 4 6
⎝4⎠ 2 4! 6!
0.707107 − 0.707103
εt = × 100% = 0.0005% ;
0.707107
0.707103 − 0.707429
εa = × 100% = −0.046%
0.707103
Terms Result Εt % Ea %
1 1 -41.42
2 0.691575 -2.19 -44.6
3 0.707429 -0.455 2.24
4 0.707103 0.0005 -0.046
4.4 Use zero- through third-order Taylor series expansions to predict f (2) for
f ( x ) = 25 x 3 − 6 x 2 + 7 x − 88
using a base point at x=1. Compute the true percent relative error εt for each
approximation.
SOLUTION:
f ′′(1)
(2 − 1)2 + f (1) (2 − 1)3 ;
′′′
f (2 ) = f (1) + f ′(1)(2 − 1) +
2 6
Zero order:
f (2 ) ≈ f (1) = −62 ;
102 − (− 62 )
εt = × 100% = 160.8%
102
First order:
f (2 ) ≈ f (1) + f ′(1)(2 − 1) = 8 ;
102 − 8
εt = × 100% = 92.1% ;
102
Second order:
Third order:
f ′′′(1) = 150 ;
f ′′(1)
(2 − 1)2 + f (1) (2 − 1)3 = 102 ;
′′′
f (2 ) = f (1) + f ′(1)(2 − 1) +
2 6
εt = 0
Terms Result Et %
1 -62 160.8
2 8 92.1
3 77 24.5
4 102 0
4.6 Use forward and backward difference approximations of O(h) and a centered
difference approximation of O(h2) to estimate the first derivative of the function
examined in Prob. 4.4. Evaluate the derivative at x=2 using a step size of h=0.25.
Compare your results with the true value of the derivative. Interpret your results on
the basis of the remainder term of the Taylor series expansion.
SOLUTION:
f ( x ) = 25 x 3 − 6 x 2 + 7 x − 88
For h=0.25
xi −1 = 1.75 , f ( xi −1 ) = 39.85938 ;
xi = 2 , f ( xi ) = 102 ;
xi +1 = 2.25 , f ( xi +1 ) = 182.1406
Interpretation:
From the formula of these three approximations
f (xi +1 ) − f (xi )
f ′(x ) = + O (h ) (Forward)
xi +1 − xi
f (xi ) − f ( xi −1 )
f ′(x ) = + O(h ) (Backward)
xi − xi −1
f (xi +1 ) − f ( xi −1 )
f ′(2 ) = − O(h 2 ) (Central)
2h
Notice that the truncation error is of the order of h2 in contrast to the forward and
backward approximations that were of the order of h. So the Taylor series analysis
yields the practical information that the centered difference is a more accurate
representation of the derivative.
SOLUTION:
f ( x ) = 25 x 3 − 6 x 2 + 7 x − 88
For h=0.2
xi = 2 , f ( xi ) = 102 ;
xi +1 = 2.2 , f ( xi +1 ) = 164.56 ;
xi −1 = 1.8 , f ( xi −1 ) = 50.92 ;
So
f (xi +1 ) − 2 f ( xi ) + f ( xi −1 ) 164.56 − 2(102 ) + 50.92
f ′′(2 ) = = = 288
h2 0. 2 2
For h=0.1
xi = 2 , f ( xi ) = 102 ;
xi +1 = 2.1 , f ( xi +1 ) = 131.765 ;
xi −1 = 1.9 , f ( xi −1 ) = 75.115 ;
So
131.765 − 2(102) + 75.115
f ′′(2 ) = = 288
0.12
Interpretation:
Both are exact, because errors are function of 4th order derivatives, which are zero for
3rd order polynomial.
4.8 Recall that the velocity of the falling parachutist can be computed by [Eq. (1.10)],
v(t ) =
gm
c
(1 − e −(c / m )t )
Use a first-order error analysis to estimate the error of v at t=6, if g=9.8 and m=50 but
c=12.5±2.
SOLUTION:
∂v cgte − (c / m )t − gm(1 − e − (c / m )t )
=
∂c c2
So
⎛ ∂v ⎞
⎜ ⎟ = −1.38666
⎝ ∂c ⎠ c =12.5
9.8 × 50
v(t )c =12.5 =
12.5
( )
1 − e −(12.5 / 50 )6 = 30.4533
So
v = 30.4533 ± 2.77332
Here
⎛ ∂v ⎞ g⎛ − ⎞
ct ct
gt −
⎜ ⎟ = ⎜⎜1 − e m ⎟⎟ − e m = 0.346665
⎝ ∂m ⎠ m =50 c ⎝ ⎠ m
∂v ~
∆m = 0.346665 × 0.5 = 0.173333
∂m
So
∆v = 2.77332 + 0.173333 = 2.946653
Then we obtain
v = 30.4533 ± 2.946653