Introduction To Numerical Methods-CH-1 New

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

INTRODUCTION, APPROXIMATION AND ERRORS

After finishing this chapter, you should be able to:


I. understand the need for numerical methods, and
II. Go through the stages (mathematical modeling, solving and implementation) of
Page | 1
solving a particular physical problem

Introduction to Numerical Methods


Numerical methods are techniques by which mathematical problems are formulated so that they
can be solved with arithmetic operations (multiplication, division, addition, subtraction).
Although there are many kinds of numerical methods, they have one common characteristic: they
invariably involve large numbers of tedious arithmetic calculations.
Mathematics is an elegant and precise subject: however when numerical answers are required
one sometimes needs to rely on approximate methods to obtain useable answers. There are many
problems which simply do not have analytical solutions, or those whose exact solution is beyond
our current state of knowledge. There are also many problems which are too long (tedious) to
solve by hand. When such problems arise we can exploit numerical analysis to reduce the
problem to one involving a finite number of unknowns and use a computer to solve the resulting
equations.

There are several additional reasons why you should study numerical methods:
1. Numerical methods are extremely powerful problem-solving tools. They are capable of
handling large systems of equations, nonlinearities, and complicated geometries thatare
not uncommon in engineering practice and that are often impossible to solve analytically.
As such, they greatly enhance your problem-solving skills.
2. During your careers, you may often have occasion to use commercially available
prepackaged, or “canned,” computer programs that involve numerical methods. The
intelligent use of these programs is often predicated on knowledge of the basic theory
underlying the methods.
3. Many problems cannot be approached using canned (recorded)programs. If you are
familiarwith numerical methods and are adept at computer programming, you can design
your own programs to solve problems without having to buy or commission expensive
software.
4. Numerical methods are an efficient vehicle for learning to use computers. It is well
known that an effective way to learn programming is to actually write computer
programs. Because numerical methods are for the most part designed for implementation
on computers, they are ideal for this purpose.
5. Numerical methods provide a vehicle for you to reinforce your understanding of
mathematics. Because one function of numerical methods is to reduce higher
mathematics to basic arithmetic operations as stated above.
Finally, the aim of numerical methods is therefore to provide systematic methods for solving
problems in a numerical form. The process of solving problems generally involves starting from
an initial data, using high precision digital computers, following the steps in the algorithms, and

Page 1 of 22
finally obtaining the results. Often the numerical data and the methods used are approximate
ones. Hence, the error in a computed result may be caused by the errors in the data, or the errors
in the method or both.

Measuring Errors
Page | 2
After finishing this topic, you should be able to:
A. find the true and relative true error,
B. find the approximate and relative approximate error,
C. relate the absolute relative approximate error to the number of significant
digits at least correct in your answers, and
D. Know the concept of significant digits.

SIGNIFICANT FIGURES
The concept of a significant figure, or digit, has been developed to formally designate the
reliability of a numerical value. The significant digits of a number are those that can be used with
confidence. They correspond to the number of certain digits plus one estimated digit. For
example, the speedometer and the odometer in Fig. below yield readings of three and seven
significant figures, respectively. For the speedometer, the two certain digits are 48. It is
conventional to set the estimated digit at one-half of the smallest scale division on the
measurement device. Thus the speedometer reading would consist of the three significant
figures: 48.5. In a similar fashion, the odometer would yield a seven-significant-figure reading of
87,324.45.

Although it is usually a straightforward procedure to ascertain the significant figures of a


number, some cases can lead to confusion. For example, zeros are not always significant figures
because they may be necessary just to locate a decimal point. The numbers 0.00001845,
0.0001845, and 0.001845 all have four significant figures. Similarly, when trailing zeros are used
in large numbers, it is not clear how many, if any, of the zeros are significant. For example, at
face value the number 45,300 may have three, four, or five significant digits, depending on
whether the zeros are known with confidence. Such uncertainty can be resolved by using

Page 2 of 22
scientific notation, where 4.53 × 104, 4.530 × 104, 4.5300 × 104 designate that the number is
known to three, four, and five significant figures, respectively.

The concept of significant figures has two important implications for our study of numerical
methods:
Page | 3
1. As we know problem, numerical methods yield approximate results. We must,
therefore, develop criteria to specify how confident we are in our approximate result. One
way to do this is in terms of significant figures. For example, we might decide that our
approximation is acceptable if it is correct to four significant figures.
2. Although quantities such as π, e, or √7 represent specific quantities, they cannot be
expressed exactly by a limited number of digits. For example,
π = 3.141592653589793238462643. . .

ACCURACY AND PRECISION


The errors associated with both calculations and measurements can be characterized with regard
to their accuracy and precision. Accuracy refers to how closely a computed or measured value
agrees with the true value. Precision refers to how closely individual computed or measured
values agree with each other. These concepts can be illustrated graphically using an analogy
from target practice. The bullet holes on each target in Fig. below can be thought of as the
predictions of a numerical technique, whereas the bull’s-eye represents the truth. Inaccuracy
(also called bias) is defined as systematic deviation from the truth. Thus, although the shots in
Fig. (c)Are more tightly grouped than those in Fig. (a), the two cases are equally biased because
they are both centered on the upper left quadrant of the target. Imprecision (also called
uncertainty), on the other hand, refers to the magnitude of the scatter. Therefore, although Fig.
(b)and (d)are equally accurate (that is, centered on the bull’s-eye), the latter is more precise
because the shots are tightly grouped.
Therefore Numerical methods should be sufficiently accurate or unbiased to meet the
requirements of a particular engineering problem. They also should be precise enough for
adequateengineering design.

Page 3 of 22
In any numerical analysis, errors will arise during the calculations. To be able to deal with the
issue of errors, we need to
A. identify where the error is coming from, followed by
B. quantifying the error, and lastly
C. Minimize the error as per our needs.
Page | 4
A. identify where the error is coming from
Error in solving an engineering or science problem can arise due to several factors. First, the
error may be in the modeling technique. A mathematical model may be based on using
assumptions that are not acceptable. For example, one may assume that the drag force on a car is
proportional to the velocity of the car, but actually it is proportional to the square of the velocity
of the car. This itself can create huge errors in determining the performance of the car, no matter
how accurate the numerical methods you may use are. Second, errors may arise from mistakes in
programs themselves or in the measurement of physical quantities. But, in applications of
numerical methods itself, the two errors we need to focus on are
I. Round off error
II. Truncation error.

Round-off Errors
Round-off error is due to the inaccuracies that arise due to a finite number of digits of precision
used to represent numbers. All computers represent numbers, except for integer and some
fractions, with imprecision.

Digital computers use floating-point numbers of fixed word length. This type of representation
will not express the exact or true values correctly. Error introduced by the omission of significant
figures due to computer imperfection is called the round-off error. Round-off errors are
avoidable in most of the computations. When n digits are used to represent a real number, then
one method is keep the first n digits and chop off all remaining digits. Another method is to
round to the nth digit by examining the values of the remaining digits.

Considera positive real number xin the normalized decimal form

x = (0.b1b2. . . bkbk+1. . .)10× 10e


We say that the number x is chopped to k digits when all digits following the kthdigits are
discarded; that is, the digits bk+1bk+2. . . are chopped off to obtain fl(x) = (0.b1b2. . . bk)10×10e.
Conversely, x is rounded to k digits when fl(x) is obtained by choosing fl(x) nearest to x; that is,
adding one to bkif bk+1≥ 5 and chop off all but the first k digits if bk+1<5

TRUNCATION ERROR
A round-off error arises in terminating the decimal expansion and rounding. In contrast, the
truncation error terminates a process. So, the truncation error generally refers to the error
involved in terminating an infinite sequence or series after a finite number of terms that is,
replacing non computable problems with computable ones. To make the idea precise,

Page 4 of 22
For example, the Maclaurin series for e x is given as
x2 x3
e  1 x 
x
  .......... ..........
2! 3!
This series has an infinite number of terms but when using this series to calculate e x , only a finite
Page | 5 number of terms can be used. For example, if one uses three terms to calculate e x , then
x2
ex  1 x  .
2!
The truncation error for such an approximation is
 x2 
Truncation error = e x  1  x  ,
 2! 
x3 x4

  .......... .......... ...
3! 4!
But, how can truncation error be controlled in this example? We can use the concept of relative
approximate error to see how many terms need to be considered. Assume that one is calculating
e1.2 using the Maclaurin series, then
1.2 2 1.2 3
e1.2  1  1.2    .......... .........
2! 3!
Let us assume one wants the absolute relative approximate error to be less than 1 %. In Table 1,
we show the value of e1.2 , approximate error and absolute relative approximate error as a
function of the number of terms, n .
n e 1 .2 Ea a %
1 1 - -
2 2.2 1.2 54.546
3 2.92 0.72 24.658
4 3.208 0.288 8.9776
5 3.2944 0.0864 2.6226
6 3.3151 0.020736 0.62550
Using 6 terms of the series yields a a < 1%.

B. quantifying the error

What is true error?


True error denoted by E t is the difference between the true value (also called the exact value)
and the approximate value.
True Error  True value – Approximate value
Relative true error
Relative true error is denoted by t and is defined as the ratio between the true error and the true
value.

Page 5 of 22
True Error
Relative True Error 
True Value
Approximate error
Approximate error is denoted by E a and is defined as the difference between the present
Page | 6 approximation and previous approximation.
Approximate Error  Present Approximation – Previous Approximation
Relative approximate error
Relative approximate error is denoted by a and is defined as the ratio between the approximate
error and the present approximation.
Approximat e Error
Relative Approximate Error 
Present Approximat ion
Example 1
The derivative of a function f (x ) at a particular value of x can be approximately calculated by
f ( x  h)  f ( x )
f ( x) 
h
of f ( 2) For f ( x)  7e 0.5 x and h  0.3 , find
a. The approximate value of f ( 2)
b. The true value of f ( 2)
c. The true error for part (a)
d. Relative true error at x  2 .
e. f ( 2) using h  0.3
f. f ( 2) using h  0.15
g. approximate error for the value of f ( 2) for part (f)
h. Relative approximate error in calculating f ( 2) using values from h  0.3 and
h  0.15 .

Solution
f ( x  h)  f ( x ) b) The exact value of f (2) can be
a) f ( x) 
h calculated by using our knowledge
For x  2 and h  0.3 , of differential calculus.
f (2  0.3)  f (2) f ( x)  7e 0.5 x
f (2) 
0 .3
f ' ( x)  7  0.5  e0.5 x
f (2.3)  f (2)
  3.5e 0.5 x
0.3
So the true value of f ' (2) is
7e 0.5( 2.3)  7e 0.5( 2)
 f ' (2)  3.5e 0.5( 2)
0.3
22.107  19.028  9.5140

0.3 c) True error is calculated as
 10.265 E t = True value – Approximate value
 9.5140  10.265
 0.75061
Page 6 of 22
The magnitude of true error does not show how bad the error is. A true error of Et  0.722
may seem to be small, but if the function given in the Example 1 were f ( x)  7  106 e 0.5 x , the
true error in calculating f ( 2) with h  0.3, would be Et  0.75061106. This value of true
error is smaller, even when the two problems are similar in that they use the same value of the
Page | 7
function argument, x  2 and the step size, h  0.3 . This brings us to the definition of relative
true error.
d) Relative true error is calculated as f (2.3)  f (2)

True Error 0.3
t 
True Value 7e 0.5 ( 2.3)
 7e 0.5 ( 2 )

 0.75061 0.3

9.5140 22.107  19.028

 0.078895 0.3
Relative true errors are also presented as  10.265
percentages. For this example, f) Repeat the procedure of part (e) with
t  0.0758895 100% h  0.15,
 7.58895% f ( x  h)  f ( x )
f ( x) 
Absolute relative true errors may also need h
to be calculated. In such cases, For x  2 and h  0.15 ,
t | 0.075888| f (2  0.15)  f (2)
f ' (2) 
= 0.0758895 0.15
= 7.58895% f (2.15)  f (2)

0.15
e) The approximate expression for the 7e 0.5 ( 2.15)
 7e 0.5( 2 )
derivative of a function is 
0.15
f ( x  h)  f ( x ) 20.50  19.028
f ' ( x)  . 
h 0.15
For x  2 and h  0.3 ,  9.8799
f (2  0.3)  f (2)
f ' (2) 
0.3
g) So the approximate error, Ea is
E a  Present Approximation – Previous Approximation
 9.8799  10.265
 0.38474
The magnitude of approximate error does not show how bad the error is . An approximate error
of E a  0.38300 may seem to be small; but for f ( x)  7  106 e 0.5 x , the approximate error in
calculating f ' (2) with h  0.15 would be Ea  0.38474106 . This value of approximate error
is smaller, even when the two problems are similar in that they use the same value of the

Page 7 of 22
function argument, x  2 , and h  0.15 and h  0.3 . This brings us to the definition of relative
approximate error.
h) The relative approximate error is calculated as
Approximat e Error
a 
Page | 8 Present Approximat ion
 0.38474

9.8799
 0.038942
Relative approximate errors are also presented as percentages. For this example,
a  0.038942 100%
=  3.8942%
Absolute relative approximate errors may also need to be calculated. In this example
a  | 0.038942|
 0.038942Or 3.8942%

Binary Representation of Numbers


After reading this chapter, you should be able to:
1. convert a base-10 real number to its binary representation,
2. Convert a binary number to an equivalent base-10 number.
In everyday life, we use a number system with a base of 10. For example, look at the
number 257.56. Each digit in 257.56 has a value of 0 through 9 and has a place value. It can be
written as
257.76  2  102  5  101  7  100  7  101  6  102
In a binary system, we have a similar system where the base is made of only two digits 0 and 1.
So it is a base 2 system. A number like (1011.0011) in base-2 represents the decimal number as
(1011.0011) 2  (1  23  0  22  1  21  1  20 )  (0  21  0  22  1  23  1  24 ) 10
 11.1875
in the decimal system.
To understand the binary system, we need to be able to convert binary numbers to
decimal numbers and vice-versa.
We have already seen an example of how binary numbers are converted to decimal
numbers. Let us see how we can convert a decimal number to a binary number. For example take
the decimal number 11.1875. First, look at the integer part: 11.
1. Divide 11 by 2. This gives a quotient of 5 and a remainder of 1. Since the remainder
is 1, a0  1 .
2. Divide the quotient 5 by 2. This gives a quotient of 2 and a remainder of 1. Since the
remainder is 1, a1  1 .
3. Divide the quotient 2 by 2. This gives a quotient of 1 and a remainder of 0. Since the
remainder is 0, a 2  0 .

Page 8 of 22
4. Divide the quotient 1 by 2. This gives a quotient of 0 and a remainder of 1. Since the
remainder is, a3  1 .
Since the quotient now is 0, the process is stopped. The above steps are summarized in Table 1.

Table 1
Page | 9 Converting a base-10 integer to binary representation.
Quotient Remainder
11/2 5 1  a0
5/2 2 1  a1
2/2 1 0  a2
1/2 0 1  a3
Hence
(11)10  (a3 a 2 a1 a0 ) 2
 (1011) 2
For any integer, the algorithm for finding the binary equivalent is given in the flow chart on the
next page.
Now let us look at the decimal part, that is, 0.1875.
1. Multiply 0.1875 by 2. This gives 0.375. The number before the decimal is 0 and the
number after the decimal is 0.375. Since the number before the decimal is 0, a1  0 .
2. Multiply the number after the decimal, that is, 0.375 by 2. This gives 0.75. The number
before the decimal is 0 and the number after the decimal is 0.75. Since the number
before the decimal is 0, a2  0 .
3. Multiply the number after the decimal, that is, 0.75 by 2. This gives 1.5. The number
before the decimal is 1 and the number after the decimal is 0.5. Since the number before
the decimal is 1, a 3  1 .
4. Multiply the number after the decimal, that is, 0.5 by 2. This gives 1.0. The number
before the decimal is 1 and the number after the decimal is 0. Since the number before
the decimal is 1, a4  1 .
Since the number after the decimal is 0, the conversion is complete. The above steps are
summarized in Table 2.

Table 2.Converting a base-10 fraction to binary representation.


Number after Number before
Number
decimal decimal
0.1875  2 0.375 0.375 0  a1
0.375  2 0.75 0.75 0  a2
0.75  2 1.5 0.5 1  a 3
0.5  2 1.0 0.0 1  a4

Page 9 of 22
Start

Integer N to be converted to
Page | 10 Input (N)10
binary format

i=0

Divide N by 2 to get quotient


Q & remainder R

i = i+1 ai = R

No

Is Q = 0?

Yes

n=i

(N)10 = (an. . .a0)2

STOP

Page 10 of 22
Hence
(0.1875)10  (a1a 2 a 3a 4 ) 2
 (0.0011) 2
The algorithm for any fraction is given in a flowchart on the next page.
Page | 11 Having calculated
(11)10  (1011) 2
and
(0.1875)10  (0.0011) 2 ,
we have
(11.1875)10  (1011.0011) 2 .
In the above example, when we were converting the fractional part of the number, we were left
with 0 after the decimal number and used that as a place to stop. In many cases, we are never
left with a 0 after the decimal number. For example, finding the binary equivalent of 0.3 is
summarized in Table 3.

Table 3.Converting a base-10 fraction to approximate binary representation.


Number after Number before
Number
decimal decimal
0.3  2 0.6 0.6 0  a1
0.6  2 1.2 0.2 1  a2
0.2  2 0.4 0.4 0  a 3
0.4  2 0.8 0.8 0  a4
0.8  2 1.6 0.6 1  a 5
As you can see the process will never end. In this case, the number can only be approximated in
binary format, that is,
(0.3)10  (a 1a  2 a 3a  4 a 5 ) 2  (0.01001) 2
Q: But what is the mathematics behinds this process of converting a decimal number to binary
format?
A: Let z be the decimal number written as
z  x. y
where
x is the integer part and y is the fractional part.
We want to find the binary equivalent of x . So we can write

Page 11 of 22
Start

Fraction F to be converted
Page | 12 Input (F)10
to binary format

i  1

Multiply F by 2 to get number


before decimal, S and after
decimal, T

i  i 1 ai = R

No

Is T = 0?

Yes

n=i

(F)10 = (a-1. . .a-n)2

STOP

Page 12 of 22
x  an 2 n  an1 2 n1  ...  a0 20
If we can now find a 0 ,. . ., a n in the above equation then
( x)10  (a n a n 1 . . .a0 ) 2
We now want to find the binary equivalent of y . So we can write
Page | 13
y  b1 2 1  b2 2 2  ...  bm 2 m
If we can now find b1 ,. . ., b m in the above equation then
( y)10  (b1b2 . . .bm ) 2
Let us look at this using the same example as before.

Example 1
Convert (11.1875)10 to base 2.

Solution
To convert (11)10 to base 2, what is the highest power of 2 that is part of 11. That power is 3, as
2 3  8 to give
11  2 3  3
What is the highest power of 2 that is part of 3. That power is 1, as 21  2 to give
3  21  1
So
11  2 3  3  2 3  21  1
What is the highest power of 2 that is part of 1. That power is 0, as 2 0  1 to give
1  20
Hence
(11)10  23  21  1  23  21  20  1 23  0  22  1 21  1 20  (1011) 2
To convert (0.1875)10 to the base 2, we proceed as follows. What is the smallest negative power
of 2 that is less than or equal to 0.1875. That power is  3 as 2 3  0.125 .
So
0.1875  23  0.0625
What is the next smallest negative power of 2 that is less than or equal to 0.0625. That power is
 4 as 2 4  0.0625 .
So
0.1875  23  24
Hence
(0.1875)10  2 3  0.0625  2 3  2 4  0  2 1  0  2 2  1 2 3  1 2 4  (0.0011) 2
Since
Page 13 of 22
(11)10  (1011) 2
and
(0.1875)10  (0.0011) 2
we get
Page | 14 (11.1875)10  (1011.0011) 2
Can you show this algebraically for any general number?
Example 2
Convert (13.875)10 to base 2.
Solution
For (13)10 , conversion to binary format is shown in Table 4.

Table 4.Conversion of base-10 integer to binary format.


Quotient Remainder
13/2 6 1  a0
6/2 3 0  a1
3/2 1 1  a2
1/2 0 1  a3

So
(13)10  (1101)2 .
Conversion of (0.875)10 to binary format is shown in Table 5.

Table 5.Converting a base-10 fraction to binary representation.


Number after Number before
Number
decimal decimal
0.875  2 1.75 0.75 1  a1
0.75  2 1.5 0.5 1  a 2
0.5  2 1.0 0.0 1  a3

So
(0.875)10  (0.111) 2
Hence
(13.875)10  (1101.111)2

Page 14 of 22
Taylor Theorem Revisited
After finishing this topic, you should be able to
1. understand the basics of Taylor’s theorem,
Page | 15
2. write transcendental and trigonometric functions as Taylor’s polynomial,
3. use Taylor’s theorem to find the values of a function at any point, given the values of the
function and all its derivatives at a particular point,
4. calculate errors and error bounds of approximating a function by Taylor series, and
5. Revisit the chapter whenever Taylor’s theorem is used to derive or explain numerical
methods for various mathematical procedures.
The use of Taylor series exists in so many aspects of numerical methods that it is imperative to
devote a separate chapter to its review and applications. For example, you must have come
across expressions such as
x2 x4 x6
cos(x)  1     (1)
2! 4! 6!
x3 x5 x7
sin( x)  x     (2)
3! 5! 7!
x2 x3
e  1 x 
x
  (3)
2! 3!
All the above expressions are actually a special case of Taylor series called the Maclaurin series.
Why are these applications of Taylor’s theorem important for numerical methods? Expressions
such as given in Equations (1), (2) and (3) give you a way to find the approximate values of these
functions by using the basic arithmetic operations of addition, subtraction, division, and
multiplication.

Example 1
Find the value of e 0.25 using the first five terms of the Maclaurin series.
Solution
The first five terms of the Maclaurin series for e x is
x2 x3 x4
ex 1 x   
2! 3! 4!
0.252 0.253 0.254
e 0.25  1  0.25   
2! 3! 4!
 1.2840
The exact value of e 0.25 up to 5 significant digits is also 1.2840.
But the above discussion and example do not answer our question of what a Taylor series is.
Here it is, for a function f x 

Page 15 of 22
f x  2 f  x  3
f x  h   f x   f  x h  h  h  (4)
2! 3!
Provided all derivatives of f x  exist and are continuous between x and x  h .
What does this mean in plain English?
Page | 16 As Archimedes would have said (without the fine print), “Give me the value of the function at a
single point, and the value of all (first, second, and so on) its derivatives, and I can give you the
value of the function at any other point”.
It is very important to note that the Taylor series is not asking for the expression of the
function and its derivatives, just the value of the function and its derivatives at a single point.
Now the fine print: Yes, all the derivatives have to exist and be continuous between x
(the point where you are) to the point, x  h where you are wanting to calculate the function at.
However, if you want to calculate the function approximately by using the n th order Taylor
polynomial, then 1st ,2 nd ,...., n th derivatives need to exist and be continuous in the closed interval
[ x, x  h] , while the (n  1) th derivative needs to exist and be continuous in the open interval
( x, x  h ) .

Example 2
 
Take f x  sinx , we all know the value of sin   1 . We also know the f x  cosx and
2
   
cos   0 . Similarly f x    sin(x) and sin   1 . In a way, we know the value of sinx 
2 2

and all its derivatives at x  . We do not need to use any calculators, just plain differential
2
calculus and trigonometry would do. Can you use Taylor series and this information to find the
value of sin2 ?
Solution

x
2
xh 2
h  2 x

 2
2
 0.42920
So
h2 h3 h4
f x  h   f x   f x h  f x   f x   f ( x) 
2! 3! 4!

x
2

Page 16 of 22
h  0.42920
   
f x  sinx , f    sin   1
2 2
 
f x  cosx , f    0
Page | 17 2
 
f x    sinx  , f    1
2
 
f x    cos(x) , f    0
2
 
f x   sin(x) , f    1
2
Hence
        h   h   h
2 3 4
f   h   f    f  h  f    f    f   
2  2 2  2  2!  2  3!  2  4!
 
f   0.42920  1  00.42920  1
0.42920
2
0
0.42920
3
1
0.42920
4

2  2! 3! 4!
 1  0  0.092106 0  0.00141393 
 0.90931
The value of sin2 I get from my calculator is 0.90930which is very close to the value I just
obtained. Now you can get a better value by using more terms of the series. In addition, you can
now use the value calculated for sin2 coupled with the value of cos2 (which can be
calculated by Taylor series just like this example or by using the sin2 x  cos2 x  1 identity) to
find value of sinx  at some other point. In this way, we can find the value of sinx  for any
value from x  0 to 2 and then can use the periodicity of sinx  , that is
sinx   sinx  2n , n  1,2, to calculate the value of sinx  at any other point.

Example 3

x3 x5 x7
Derive the Maclaurin series of sinx   x    
3! 5! 7!
Solution

In the previous example, we wrote the Taylor series for sinx  around the point x  .
2
Maclaurin series is simply a Taylor series for the point x  0 .
f x  sinx , f 0  0
f x  cosx , f 0  1
f x    sinx  , f 0  0

Page 17 of 22
f x    cosx  , f 0  1
f x   sinx , f 0  0
f x   cos(x) , f 0  1

Page | 18 Using the Taylor series now,


h2 h3 h4 h5
f x  h   f x   f x h  f x   f x   f x   f x   
2! 3! 4 5
2 3 4
h5
f 0  h   f 0  f 0h  f 0  f 0  f 0  f 0  
h h h
2! 3! 4 5
2 3 4 5
f h   f 0  f 0h  f 0  f 0  f 0  f 0  
h h h h
2! 3! 4 5
2 3 4 5
h h h h
 0  1h   0 1  0 1 
2! 3! 4 5
3 5
h h
 h  
3! 5!
So
x3 x5
f x   x   
3! 5!

x3 x5
sinx   x    
3! 5!
Example 4
Find the value of f 6 given that f 4  125 , f 4  74 , f 4  30 , f 4  6 and all other
higher derivatives of f x  at x  4 are zero.
Solution

h2 h3
f x  h   f x   f x h  f x   f x   
2! 3!

x4
h  64
2
Since fourth and higher derivatives of f x  are zero at x  4 .
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

Page 18 of 22
Note that to find f 6 exactly, we only needed the value of the function and all its derivatives at
some other point, in this case, x  4 . We did not need the expression for the function and all its
derivatives. Taylor series application would be redundant if we needed to know the expression
for the function, as we could just substitute x  6 in it to get the value of f 6 .
Page | 19 Actually the problem posed above was obtained from a known function
f x   x 3  3x 2  2 x  5 where f 4  125 , f 4  74 , f 4  30 , f 4  6 , and all other
higher derivatives are zero.

Error in Taylor Series


As you have noticed, the Taylor series has infinite terms. Only in special cases such as a finite
polynomial does it have a finite number of terms. So whenever you are using a Taylor series to
calculate the value of a function, it is being calculated approximately.
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
f x  h   f x   f x h  f ' ' x     f x   Rn x 
n 
2! n!
Where the remainder is given by

Rn x    x  h
n 1
f n 1 c  .
(n  1)!
Where
xc xh
That is, c is some point in the domain x, x  h .
Example 5
The Taylor series for e x at point x  0 is given by
x2 x3 x4 x5
e  1 x 
x
   
2! 3! 4! 5!
a) What is the truncation (true) error in the representation of e 1 if only four terms of the series
are used?
b) Use the remainder theorem to find the bounds of the truncation error.
Solution
a) If only four terms of the series are used, then
x2 x3
ex  1 x  
2! 3!
12 13
e1  1  1  
2! 3!
 2.66667
The truncation (true) error would be the unused terms of the Taylor series, which then are

Page 19 of 22
x4 x5
Et   
4! 5!
14 15
  
4! 5!
Page | 20  0.0516152
b) But is there any way to know the bounds of this error other than calculating it directly?
Yes,
hn
f x  h   f x   f x h    f n  x   Rn  x 
n!
Where

Rn  x  
x  h n1 f n1 c  ,
x  c  x  h , and
n  1!
c is some point in the domain x, x  h . So in this case, if we are using four terms of the Taylor
series, the remainder is given by x  0, n  3

R3  x  
0  1
31
f 31 c 
3  1!

1
f 4 
c 
4!
ec

24
Since
x c  xh
0  c  0 1
0  c 1
The error is bound between
e0 e1
 R3 1 
24 24
 R3 1 
1 e
24 24
0.041667  R3 1  0.113261
So the bound of the error is less than 0.113261 which does concur with the calculated error of
0.0516152.
Example 6
The Taylor series for e x at point x  0 is given by
x2 x3 x4 x5
ex  1 x     
2! 3! 4! 5!

Page 20 of 22
As you can see in the previous example that by taking more terms, the error bounds decrease and
hence you have a better estimate of e 1 . How many terms it would require to get an
approximation of e 1 within a magnitude of true error of less than 106 ?
Solution
Page | 21 Using n  1 terms of the Taylor series gives an error bound of

Rn  x  
x  h n1 f n 1 c 
n  1!
x  0, h  1, f ( x)  e x

Rn 0  
0  1
n 1
f n 1 c 
n  1!

 1n 1 e c
n  1!
Since
xc xh
0  c  0 1
0  c 1
 Rn 0 
1 e
(n  1)! (n  1)!
So if we want to find out how many terms it would require to get an approximation of e 1 within
a magnitude of true error of less than 106 ,
e
 10 6
(n  1)!
(n  1)! 106 e
(n  1)! 106  3 (As we do not know the value of e but it is less than 3).
n9
So 9 terms or more will get e 1 within an error of 106 in its value.
We can do calculations such as the ones given above only for simple functions. To do a
similar analysis of how many terms of the series are needed for a specified accuracy for any
general function, we can do that based on the concept of absolute relative approximate errors
discussed above as follows.
We use the concept of absolute relative approximate error, which is calculated after each
term in the series is added. The maximum value of m , for which the absolute relative
approximate error is less than 0.5  102 m % is the least number of significant digits correct in the
answer. It establishes the accuracy of the approximate value of a function without the
knowledge of remainder of Taylor series or the true error.

Page 21 of 22
EXCERSICE ON CHAPTER-1
1. Convert the following base-2 numbers to base-10: (a) 1011001,
(b) 110.00101 and (c) 0.01011 Ans.(a).89 (b).6.15625
2. Convert (327)10 and (0.3125)10 to binary.
Ans. (101000111)2 , (0.0101)2
Page | 22 3. Represent the number 50824.6135 in the decimal system (base-10).
4. Given the number π is approximated using n = 5 decimal digits.
a. Determine the relative error due to chopping and express it as a per cent.
Ans. 0.002949%
b. Determine the relative error due to rounding and express it as a per cent.
Ans. 0.0002338%.
5. Use Taylor series expansions (zero through fourth order) to predict f (2) for f (x) = ln(x) with
a base point at x = 1. Determine the true percentage relative error for each approximation.
Ans. 100%, 44.27%, 27.87%, 20.22%, 15.84% respectively.
6. Given two numbers a = 8.8909 × 103 and b = 8.887 × 103. Calculate the difference between
the two numbers (a – b) using decimal floating point approximation (scientific notation) with
three significant digits by (a) chopping (b) rounding.
Ans. (a) 3, (b) 4
7. Given the trigonometric function f (x) = sin x,
a. Expand f (x) about x = 0 using Taylor series
b. Truncate the series to n = 6 terms
c. Find the relative error at x = π/4 due to truncation in (b)
d. Determine the upper bound on the magnitude of the relative error at x = π/4 and
express it as a percent.
( ( )( )
Ans. (a) ( ) ∑ (b) ( ) , (c) 0.005129%,
(d) 0.02305%
8. Show that the relative error Erxy of the product where x = xe + Δx and y = ye + Δy is Erxy =
Erx +Ery. Assume |Erx| << 1 and |Ery| << 1.
9. Show that the relative error Erxy of the quotient where x = xe + Δx and y = ye + Δy is Erxy =
Erx – Ery.Assume |Erx| << 1 and |Ery| << 1.
10. If the number x = 57.46235 is rounded off to four significant figures, find the absolute error,
relative error and the percentage relative error.
Ans. Abs.err = 0.00235; Rela.err= 4.089634 × 10–5, Per.rela.err= 4.08964 ×10–3
11. Evaluate e−5 using two approaches

Include six terms in the series and compute the percentage relative error and approximate
estimate of the error for each term when estimating e0.5.
Ans. Percentage relative error = 9.02%; Approximate estimate of error = 33.3% with 6
terms included approximate error falls below Es = 0.05%

Page 22 of 22

You might also like