Introduction To Numerical Methods-CH-1 YG
Introduction To Numerical Methods-CH-1 YG
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 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:
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. . .
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.
This is the same expression you would have obtained by directly using the formula from your differential
calculus class
d n
( x ) nx n1
dx
By this formula for
f ( x) x 2
f ( x ) 2 x
The exact value of f (3) is
f (3) 2 3 6
If we now choose x 0.2 , we get
Exact calculations require us to calculate the area under the curve by adding the area of the
rectangles as shown in Figure 2. However, exact calculations require an infinite number of such
rectangles. Since we cannot choose an infinite number of rectangles, we will have truncation error.
For example, to find
9
x
2
dx ,
3
x dx ( x 2 ) (6 3) ( x 2 ) (9 6)
2
x 3 x 6
3
(32 )3 (6 2 )3
27 108 135
y
90
y = x2
60
30
0 x
0 3 6 9 12
Again, we purposefully chose a simple example because we wanted to have no round off error
in our calculations. This makes the obtained error purely truncation. The truncation error is
234 135 99
Can you reduce the truncation error by choosing more rectangles as given in Figure 3? What is the
truncation error?
y
90
y = x2
60
30
0 x
0 1.5 3 4.5 6 7.5 9 10.5 12
Figure Plot of y x 2 showing the approximate area under the curve from x 3
to x 9 using four rectangles.
Solution
a) The approximate value of f (2) b) The exact value of f (2) can be calculated by
f ( x h) f ( x ) using our knowledge of differential calculus.
f ( x)
h f ( x) 7e 0.5 x
For x 2 and h 0.3 , f ' ( x) 7 0.5 e0.5 x 3.5e
0.5 x
f (2 0.3) f (2)
f (2) So the true value of f ' ( 2) is
0.3
f ' (2) 3.5e 0.5( 2) 9.5140
f (2.3) f (2)
c) True error is calculated as
0.3
Et = True value – Approximate value
7e 0.5 ( 2.3)
7e 0.5 ( 2 )
9.5140 10.265 0.722
0.3
22.107 19.028
10.263
0.3
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
6
calculating f (2) with h 0.3, would be Et 0.722 10 . This value of true error is smaller, even
when the two problems are similar in that they use the same value of the 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 Absolute relative true errors may also need to be
True Error calculated.
t
True Value
In such cases,
0.722
t | 0.075888 |
9.5140
0.0758895 = 0.0758895
Relative true errors are also presented as = 7.58895 %
percentages. For this example,
t 0.0758895 100% e) The approximate expression for the
derivative of a function is
7.58895%
Table
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 a2 a1a0 ) 2
(1011) 2
For any integer, the algorithm for finding the binary equivalent is given in the flow chart on the next page.
Fraction F to be converted
Input (F) 10
to binary format
i 1
ai = R
i i 1
Is T = 0?
No
Yes
n=i
(F) 10 = (a-
1 . . .a-n ) 2
STOP
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.
So
(0.875)10 (0.111) 2
Example
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.25 2 0.25 3 0.25 4
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
f x 2 f x 3
f x h f x f x h h h (4)
2! 3!
Example 2
Take f x sinx , we all know the value of sin 1 . We also know the f x cosx and
2
cos 0 . Similarly, f x sin(x) and sin 1 . In a way, we know the value of sinx and
2 2
all its derivatives at x . We do not need to use any calculators, just plain differential calculus and
2
trigonometry would do. Can you use Taylor series and this information to find the value of sin2 ?
Solution
x
2
xh2
h 2 x 2 0.42920
2
So
h2 h3 h4
f x h f x f x h f x f x f ( x)
2! 3! 4!
x
2
h 0.42920
f x sinx , f sin 1
2 2
f x cosx , f 0
2
2 2! 3! 4!
1 0 0.092106 0 0.00141393
0.90931
The value of sin2 I get from my calculator is 0.90930 which 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 sin2 coupled with the value of cos2 (which can be calculated by Taylor series just like
this example or by using the sin 2 x cos2 x 1 identity) to find value of sinx at some other point. In
this way, we can find the value of sinx for any value from x 0 to 2 and then can use the
periodicity of sinx , that is sinx sinx 2n , n 1,2, to calculate the value of sinx at any
other point.
Example 3
x3 x5 x7
Derive the Maclaurin series of sinx x
3! 5! 7!
Solution
In the previous example, we wrote the Taylor series for sinx around the point x . Maclaurin series
2
is simply a Taylor series for the point x 0 .
f x sinx , f 0 0
f x cosx , f 0 1
f x sinx , f 0 0
f x cosx , f 0 1
f x sinx , f 0 0
f x cos(x) , f 0 1
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!
x4
h 64 2
Since fourth and higher derivatives of f x are zero at x 4 .
22 23
f 4 2 f 4 f 42 f 4 f 4
2! 3!
2 2 23
f 6 125 742 30 6
2! 3!
125 148 60 8 341
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 .
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.
Rn x
x hn1 f n 1 c .
(n 1)!
Where
xc xh
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
ex 1 x
2! 3! 4! 5!
a) What is the truncation (true) error in the representation of e1 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
x4 x5
Et
4! 5!
14 15
4! 5!
0.0516152
b) But is there any way to know the bounds of this error other than calculating it directly? Yes,
n
f x h f x f x h f n
x h Rn x
n!
Where
Rn x
x hn1 f n 1 c , x c x h , and
n 1!
R3 x
0 131 f 31 c
3 1!
ec
f c
1 4
4! 24
Since
xc xh
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!
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 e1 . How many terms it would require to get an approximation of e1 within
a magnitude of true error of less than 10 6 ?
Solution
Using n 1 terms of the Taylor series gives an error bound of
Rn x
x hn1 f n 1 c
n 1!
x 0, h 1, f ( x) e x
Rn 0
0 1
n 1
f n 1
c 1
n 1
ec
n 1! n 1!
Since
xc xh
0 c 0 1
0 c 1