0% found this document useful (0 votes)
36 views7 pages

Numerical Methods - Mclaurin Series

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Numerical Methods - Mclaurin Series

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Homework #1 Solution

1. Determine machine epsilon in both double and single precision for Excel Visual
Basic.

SOLUTION:

For single precision:

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

For double precision:

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

4.2 Maclaurin series expansion for cos x is

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:

We use Eq. 3.7 in the textbook:

ε s = (0.5 × 10 2− n )%

We choose n=2, so εt=0.5%

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

Notice that ε a = 0.046% < ε s = 0.5% , so we stop here.

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:

In this problem, the Taylor series can be written as

f ′′(1)
(2 − 1)2 + f (1) (2 − 1)3 ;
′′′
f (2 ) = f (1) + f ′(1)(2 − 1) +
2 6

The true value of f(2) is f(2)=102.

Zero order:

f (2 ) ≈ f (1) = −62 ;
102 − (− 62 )
εt = × 100% = 160.8%
102

First order:

f ′(1) = 75(1) − 12(1) + 7 = 70 ;


2

f (2 ) ≈ f (1) + f ′(1)(2 − 1) = 8 ;
102 − 8
εt = × 100% = 92.1% ;
102

Second order:

f ′′(1) = 150(1) − 12 = 138 ;


f ′′(1)
f (2 ) ≈ f (1) + f ′(1)(2 − 1) + (2 − 1)2 = 77 ;
2
102 − 77
εt = × 100% = 24.5%
102

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

The first derivative of f(x) is:


f ′(x ) = 75 x 2 − 12 x + 7

The true value at x=2 is:


f ′(2) = 283

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

Forward [See Eq.(4.17) in the textbook]:


f ( xi +1 ) − f ( xi ) 182.1406 − 102
f ′(2 ) = = = 320.5625
xi +1 − xi 0.25
ε t = −13.273%
Backward [See Eq.(4.20) in the textbook]:
f ( xi ) − f ( xi −1 ) 102 − 39.85938
f ′(2 ) = = = 248.5625
xi − xi −1 0.25
ε t = 12.17%

Central [See Eq. (4.22) in the textbook]:


f ( xi +1 ) − f (xi −1 ) 182.1406 − 39.85938
f ′(2 ) = = = 284.5625
2h 0.5
ε t = −0.55%

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.

4.7 Use a centered difference approximation of O(h2) to estimate the second


derivative of the function examined in Prob. 4.4. Perform the evaluation at x=2 and
h=0.2 and 0.1. Compare your estimates with the true value of the second 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

The second derivative of f(x) is:


f ′′( x ) = 150 x − 12

The true value is:


f ′′(2 ) = 288

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

Use Eq. (4.25) in the textbook


∂v ~
∆v(c~ ) = ∆c = 1.38666 × 2 = 2.77332
∂c

9.8 × 50
v(t )c =12.5 =
12.5
( )
1 − e −(12.5 / 50 )6 = 30.4533

So
v = 30.4533 ± 2.77332

4.9 Repeat Prob. 4.8 with g=9.8, t=6, c=12.5±2, m=50±0.5.


SOLUTION:

Use Eq. (4.27) in the textbook


~ ) = ∂v ∆c~ + ∂v ∆m
∆v(c~, m ~
∂c ∂m

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

We know from last problem


∂v ~
∆c = 2.77332
∂c

So
∆v = 2.77332 + 0.173333 = 2.946653

Then we obtain
v = 30.4533 ± 2.946653

You might also like