Numerical Method Using Mathcad
Numerical Method Using Mathcad
Mathcad Release 14
PUBLICATIONS
SDC
www.schroff.com
Copyrighted Material
CHAPTER 2
Analysis of problems in engineering and the physical sciences typically involves four steps as follows. (1) Development of a suitable mathematical model that realistically represents a given physical system. (2) Derivation of the system governing equations using physical laws such as Newton's laws of motion, conservation of energy, the laws governing electrical circuits etc. (3) Solution of the governing equations, and (4) Interpretation of the results.
Copyrighted Material
Because real world problems are generally quite complex with the generation of closed-form analytical solutions becoming impossible in many situations, there exists, most definitely, a need for the proper utilization of computer-based techniques in the solution of practical problems. The advancement of computer technology has made the effective use of numerical methods and computer-based techniques very feasible, and thus, solutions can now be obtained much faster than ever before and with much better than acceptable accuracy. However, there are advantages as well as disadvantages associated with any numerical procedure that is resorted to , and these must be kept in mind when using it.
Copyrighted Material
Copyrighted Material
2.3
It is indeed possible for miscalculations to creep into a numerical solution because of various sources of error. These include inaccurate mathematical modeling, wrong programming, wrong input, rounding off of numbers and truncation of an infinite series. Round-off error is the general name given to inaccuracies that affect the calculation scene when a finite number of digits are assigned to represent an actual number. In a long sequence of calculations, this round-off error can accumulate, then propagate through the process of calculation and finally grow very rapidly to a significant number. A truncation error results when an infinite series is approximated by a finite number of terms, and, typically, upper bounds are placed on the size of this error. The true error is defined as the difference between the computed value and the true value of a number.
Copyrighted Material
ETrue = XComp XTrue
while the relative true error is the error relative to the true value
Copyrighted Material
er = XComp XTrue XTrue er = XComp XTrue XTrue 100 (%)
(2.1)
(2.2)
2.4
The Taylor series is considered as a basis of approximation in numerical analysis. If the value of a function of x is provided at " x 0 ", then the Taylor series provides a means of evaluating the function at " x 0 + h", where " x 0 " is the starting value of the independent
(2.3)
variable and " h " is the difference between the starting value and the new value at which the function is to be approximated
3 h d h d2 d f x0 + f x 0 + ..................... f x 0 + h = f x 0 + h f x 0 + 3! dx 3 dx 2! dx2 3
( )
( )
(2.4)
This equation can be used for generating various orders of approximations as shown below. The order of approximation is defined by the highest derivative included in the series. For example, If only terms up to the second derivative are retained in the series, the result is a second order approximation.
Copyrighted Material
( )
d dx f x0
( )
(2.5)
f x0 + h = f x0 + h
( )
d dx
f x0
( )
2 2
f x0
( )
(2.6)
dx
f x0 + h = f x0 + h
It is to noted that the significance of the higher order terms in the Taylor series increases with the nonlinearity of the function involved as well as the difference between the " starting x" value and the "x" value at which the function is to be approximated. Thus , the fewer the terms that are included in the series, the larger will be the error associated with the computation of the function value. If the function is linear , however, only terms up to the first derivative term need to be included. Example 2.1
Copyrighted Material
( )
d dx f x0 +
( )
2!
dx
f x0 + 2
( )
3!
dx
f x 0 + ...........................
( )
(2.7)
determine the zeroth, first, second, third, fourth and fifth order approximations of f(x0 + h ) where x0 = 0 and h = 1,2, 3, 4,5 and compare these with the exact solutions. h=1.0: Put in the function and generate its derivatives: f ( x ) := 0.15 x 0.17 x 0.25 x 0.25x + 1.25:= 0 x0
3 2 2 4 3 2
Copyrighted Material
- 0.25 x 2 -0.25 x + 1.25 h := 1. <--Generate derivatives
Copyrighted Material
f5prime ( x ) := 0.
ftaylor0 := term1
Copyrighted Material
term2 := h fprime ( x0) term3 := term5 := h
4
f2prime ( x0)
f3prime ( x0)
24
120
f5prime ( x0)
<---- first order approximation with two terms <---second order approximation with 3 terms <---third order approximation with 4 terms
ftaylor4 := term1 + term2 + term3 + term4 + term5 <---fourth order approximation with 5 terms ftaylor5 := term1 + term2 + term3 + term4 + term5 + term6 x := x0 + h x=1 <----fifth order approximation with 6 terms
Copyrighted Material
ftaylor2 = 0.75 <-ftaylor4 = 0.43 ftaylor5 = 0.43 <---EXACT ANSWER USING FUNCTION GIVEN.
These are the zero- fifth order approximations of the given function f(x) using the Taylor series.
f ( 1) = 0.43
err0 := f ( x ) ftaylor0 err0 = 0.82 err1 := f ( x ) ftaylor1 err2 := f ( x ) ftaylor2 err3 := f ( x ) ftaylor3 err4 := f ( x ) ftaylor4 err5 := f ( x ) ftaylor5
Copyrighted Material
err1 = 0.57 err2 = 0.32 err3 = 0.15 err4 = 0 err5 = 0
These are errors ( differences between exact <-- values and approximations ) for the above zero - fifth order approximations.
Similarly, by using h= 2, 3, 4, 5 , the zeroth- fifth order approximations for f(2), f(3), f(4), f(5) and the associated errors can be determined. These are given in Tables 2.1 and 2.2 Plots of the various Taylor series approximations of the given function and associated errors are generated below and are presented in Figs. 2.1 and 2.2
Copyrighted Material
x0 := 0
ftaylor0 ( x ) := f ( x0)
ftaylor1 ( x ) := ftaylor0 ( x ) + ( x x0) fprime ( x0) ftaylor2 ( x ) := ftaylor1 ( x ) + ftaylor3 ( x ) := ftaylor2 ( x ) + ( x x0) 2 ( x x0) 6
3 2
Copyrighted Material
x := 0 , 0.01 .. 5 f3prime ( x0)
4
<---first-order approximation
<---third-order approximation
ftaylor4 ( x ) := ftaylor3 ( x ) +
ftaylor5 ( x ) := ftaylor4 ( x ) +
Copyrighted Material
( x x0) 24 f4prime ( x0) ( x x0) 120
5
<---fourth-order approximation
err0 ( x ) := f ( x ) ftaylor0 ( x ) err1 ( x ) := f ( x ) ftaylor1 ( x ) err2 ( x ) := f ( x ) ftaylor2 ( x ) err3 ( x ) := f ( x ) ftaylor3 ( x ) err4 ( x ) := f ( x ) ftaylor4 ( x )
Copyrighted Material
First order approximation: Second order approximation: Third order approximation: Fourth order approximation: Fifth order approximation: err5 ( x ) := f ( x ) ftaylor5 ( x ) The various approximations generated by the above calculations and the associated errors are compared in the Table 2.1.
Copyrighted Material
Copyrighted Material
Taylor series approx of given function
50 0 ftaylor0( x) ftaylor3( x) ftaylor5( x) 50
Copyrighted Material
100
Zeroth order approx Third order approx Fifth order approx/ given function
1 2 3 x
150
x- value
Figure 2.1. Taylor series approximation of given function
x := 0 , 0.01 .. 5
errors as function of x
Copyrighted Material
Errors gen due to Taylor-series approx
50 0 50 100
Figure 2.2. Errors associated with the various Taylor series approximations
Copyrighted Material
150 0 1 2 3 4 x
x- value
The various approximations generated by the above calculations and the associated errors are compared in the following tables. Table 2.1
h := 1 .. 5
x := 0 , 1 .. 5
Copyrighted Material
Various orders of approximation generated by Taylor series approach versus true values of given function first order second order third order fourth order zeroth order fifth order
0 1 2 3 4 5 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1 0.75 0.5 0 0.25 1.25 0.75 1.25 0.58 1.25 0.43 1.25 0.43 -0.25 -1.75 -3.75 -6.25 -1.61 -6.34 -27.5 -4.01 -4.01 -18.49 -53.03 -18.49 -53.03 -14.63
True Value
x = h=
1 2 3 4 5
Copyrighted Material
-121.25 -121.25
x = h=
1 2 3 4 5
Copyrighted Material
zeroth order first order second order third order fourth order err0 ( x ) =
0 -0.82 -5.26
err1 ( x ) =
err2 ( x ) =
0 -0.32 -3.76
err3 ( x ) =
0 -0.15 -2.4
err4 ( x ) =
0 0 0 0 0 0
0 1 2 3 4 5
-0.57 -4.76
-18.99 -53.28
-121.25
PROBLEMS
2.1.
Using the Taylor series expansion for cos x, which is given as f(x) = cos x = 1- x 2 / 2 + x
4
Copyrighted Material
/ 24 ,
rad and h = 0. 1, 0.2 ....1.0 rad , and compare these with the exact solution. Using Mathcad, generate plots of the various Taylor series approximations and associated errors as functions of the independent variable x. 2.2 Develop a Taylor series expansion of the following function: f(x) = x 5 - 6 x 4 + 3x 2 + 9 .
Copyrighted Material
f(x) = x
3
Use x =3 as the base and h as the increment. Using Mathcad, evaluate the series for h= 0.1, 0.2....1.0, adding terms incrementally as in Problem 2.1. Compare the various Taylor series approximations obtained with true values in a table. Generate plots of the approximations and associated errors as functions of x .
2.3
determine f ( x0 + h ) with the help of a Taylor series expansion, where x 0 = 2 and h = 0.4. Compare the true value of f ( 2.4 ) with estimates obtained by resorting to (a) one term only (b) two terms (c) three terms and (d) four terms of the series. 2.4 Given the following function f ( x ) = 3 x 6 x + 15 x + 25
3 2
Copyrighted Material
+ 5 x + 10 ,
use a Taylor series expansion to determine the zeroth, first, second and third order approximations of f(x0 +h) where x 0 = 2 and h = 0.5. Compare these with the exact solution.
2.5
about x = 0 , determine the fourth-order approximation of e 2.5 and compare it with the exact solution. 2.6. By developing a Taylor series expansion for
about x = 0, determine the fourth-order approximation of ln (0.5) and compare it with the exact solution
2.7.
about x = 1, determine the third-order approximation of f(1.2) and compare it with the exact solution.
Copyrighted Material
f(x) = x3 e - 5x f(x) = e cos x
2.8.
about x =0 , determine the fourth- order approximation of f (2) and compare it with the exact solution. .
2.9.
Copyrighted Material
f(x) = x2 - 5 x
0.5
about x = 2, determine the third-order approximation of f (2.2), that is, (0.2) 1/2 , and compare it with the exact solution.
2.10.
use a Taylor series expansion to determine the first, second , third and fourth order approximations of f (2.5 ) by resorting to x 0 = 2 and h = 0.5 . Compare these with the exact solution. 2.11.
Copyrighted Material
+6, f(x) = 6 x3 - 9 x2 +25 x + 40 ,
use a Taylor series expansion to determine the zeroth, first, second and third order approximations of f (x0 + h ) where x 0 = 3 and h = 1 . Compare these with the exact solution. 2.12. Given the function
use a Taylor series expansion to determine the zeroth, first, second , third and fourth order
Copyrighted Material
f(x) = 4 x4 - 7 x3 + 5 x2 - 6 x + 90
approximations of f (x 0 + h ) ) where x 0 = 3 and h = 0.5 . Compare these with the exact solution. Calculate errors abnd generate calculations to three decimal places.
2.13.
Copyrighted Material
f(x) = 8 x3 - 10 x2 + 25 x + 45 , f(x) = 1 + x + x 2 / 2! + x3 / 3! +x4 / 4!
use a Taylor series expansion to determine the zeroth, first, second and third order approximations of f (x0 + h ) where x 0 = 2 and h = 1 . Compare these with the exact solution. 2.14. Given the function
use a Taylor series expansion to determine the zeroth, first, second , third and fourth order approximations of f (x0 + h ) where x 0 = 0 and h = 0.5 . Compare these with the exact solution. Generate answers correct to four decimal places. 2.15. Given the function
Copyrighted Material
f(x) = x + x 3 / 3 + 2 x5 / 15
use a Taylor series expansion to determine the zeroth, first, second , third and fourth order approximations of f (x0 + h ) where x 0 = 0 and h = 0.8 . Compare these with the exact solution by computing percentage errors. Generate answers correct to four decimal places.
2.16.
use a Taylor series expansion to determine the fifth order approximation of f (x0 + h ) where x 0 = 0 and h = 0.2 radians . Compare your answer with the true value. Generate answers correct to four decimal places. 2.17. Given the function
Copyrighted Material
f(x) = sin (x) f(x) = 3 x2 - 6 x
0.5
use a Taylor series expansion to determine the zeroth, first, second , third and fourth order approximations of f (x0 + h ) whereo x 0 = 3 and h = 1 . Compare these with the exact solution by computing percentage errors. Generate answers correct to four decimal places.
Copyrighted Material
+9,