Académique Documents
Professionnel Documents
Culture Documents
|p|
b) Absolute error: |p p| = | 3.1416| = 7.3464 106 .
|
Relative error: |pp
= |3.1416|
= 2.3384 106 .
|p|
Problem 2: Find the largest interval in which p must lie to approximate
relative error at most 105 for each value for p.
Solution: The relative error is defined as
|pp |
|p| ,
2 with
2. We have
| 2 p |
105.
2
Therefore,
| 2 p | 2 105 ,
or
2 105
2 p 2 105,
2 2 105
p
2 + 2 105 ,
2 + 2 105
p
2 2 105.
Hence,
2 105 p
2+
2 105 .
Problem 3: Use the 64-bit long real format to find the decimal equivalent of the following
floating-point machine numbers.
a) 0 10000001010 10010011000000 0
b) 1 10000001010 01010011000000 0
Solution:
a) Given a binary number (also known as a machine number)
0 10000001010
0} ,
|{z}
|
|
{z
} 10010011000000
{z
s
Problem 4: Find the next largest and smallest machine numbers in decimal form for the
numbers given in the above problem.
Solution:
a) Consider a binary number (also known as a machine number)
0 10000001010 10010011000000 00 ,
The next largest machine number is
0 10000001010 10010011000000 01 .
(1)
2
2
2
2
2
(2)
1
Note that
N
X
2n = 2N +1 1.
n=0
The formula above is a specific case of the following more general equation:
N
X
2n = 2N +1 2M .
n=M
.
2
2
2
n=M
To get some intuition about these formulas, consider an example with M = 2 and N = 5, for instance.
Therefore, this binary number (in (2)) represents the decimal number
(1)s 2c1023(1 + f ) = (1)0 210341023 (1 + 0.57421875 0.0000000000000002220446 . . .)
= 211 (1.57421875 2.220446 . . . 1016)
= 3224 4.547473508 1013
= 3224 0.0000000000004547473508
= 3223.9999999999995452527 . . . X
b) Consider a binary number
1 10000001010 01010011000000 0
The next largest (in magnitude) machine number is
1 10000001010 01010011000000 1
(3)
(4)
2
2
2
2
2
= 0.32421875 2.220446049250313 . . . 1016
= 0.32421875 0.0000000000000002220446 . . .
= 0.32421874999999977795539 . . .
Therefore, this binary number (in (4)) represents the decimal number
(1)s 2c1023(1 + f ) = (1)1 210341023 (1 + 0.32421875 0.0000000000000002220446 . . .)
= 211 (1.32421875 2.220446049250313 . . . 1016)
= 2712 + 4.547473508864641 1013
= 2712 + 0.0000000000004547473508
= 2711.9999999999995452527 . . .
5
Problem 5: Use four-digit rounding arithmetic and the formulas to find the most accurate approximations to the roots of the following quadratic equations. Compute the
relative error.
1
a) 13 x2 123
4 x + 6 = 0;
2
b) 1.002x + 11.01x + 0.01265 = 0.
Solution: The quadratic formula states that the roots of ax2 + bx + c = 0 are
b b2 4ac
x1,2 =
.
2a
1
a) The roots of 13 x2 123
4 x + 6 = 0 are approximately
x1 = 92.24457962731231,
x2 = 0.00542037268770.
We use four-digit rounding arithmetic to find approximations to the roots. We find the
first root:
q
2
123
123
+
4 13 16
30.75 + 30.752 4 0.3333 0.1667
4
4
x1 =
=
2 0.3333
2 13
123 2
4
2 13
30.75 945.4
30.75 30.75
=
=
= 0.
0.6666
0.6666
has the following relative error:
x2
123
4
1
3
1
6
30.75
|x2 x2|
|0.00542037268770 0|
=
= 1.0.
|x2 |
0.00542037268770
We obtained a very large relative error, since the calculation for x2 involved the subtraction
of nearly equal numbers. In order to get a more accurate approximation to x2 , we need
to use an alternate quadratic formula, namely
2c
x1,2 =
.
b b2 4ac
Using four-digit rounding arithmetic, we obtain:
x2 =
123
4
1
6
123 2
4
= f l(0.00541951) = 0.005420,
4
1
3
1
6
x2 = 10.98687487643590.
2c
2 0.01265
=
2
b + b 4ac
11.01 11.012 + 4 1.002 0.01265
0.02530
0.02530
=
= 0.001149, X
11.01 + 11.00
22.01
x2 =
=
2 1.002
2.004
Similar Problem
The roots of 1.002x2 11.01x + 0.01265 = 0 are approximately
x1 = 10.98687487643590,
x2 = 0.00114907565991.
We use four-digit rounding arithmetic to find approximations to the roots. We find the
first root:
p
x1 =
=
2 1.002
2.004
2c
2 0.01265
p
=
2
b b 4ac
11.01 (11.01)2 4 1.002 0.01265
0.02530
0.02530
=
= 0.001149, X
11.01 11.00
22.01
0.d1 . . . dk dk+1 . . . 10n 0.d1 . . . dk 10n
0.d1 . . . dk dk+1 . . . 10n
k zeros
z }| {
0. 0 . . . 0 dk+1 . . . 10n
0.d1 . . . dk dk+1 . . . 10n
0.dk+1dk+2 . . . 10nk
0.d1d2 . . . 10n
0.dk+1dk+2 . . .
k
0.d1d2 . . . 10
|0.dk+1dk+2 . . . |
10k
|0.d1d2 . . . |
|0.dk+1dk+2 . . . |
since d1 1, so |0.d1d2 . . . | 0.1
10k
0.1
0.5
since dk+1 5, by assumption
10k
0.1
5 10k = 0.5 10k+1 . X
Case : dk+1 5.
n
n
nk )
y f l(y)
= 0.d1 . . . dk dk+1 . . . 10 (0.d1 . . . dk 10 + 10
y
0.d1 . . . dk dk+1 . . . 10n
0.d1 . . . dk dk+1 . . . 10n (0.d1 . . . dk + 10k ) 10n
=
0.d1d2 . . . 10n
0.d1 . . . dk dk+1 . . . 10n 0.d1 . . . k 10n
=
where k = dk + 1
0.d1d2 . . . 10n
=
k1 00 s
z }| {
z }| {
|0. 0 . . . 0 dk dk+1 . . . 0. 0 . . . 0 k |
0.d1d2 . . .
Note that 0.0 . . .0 k > 0.0 . . .0 dk dk+1 . . . ,
and k = dk + 1, dk+1 5.
For example, dk = 1, dk+1 = 6, k = 2.
k1 00 s
z }| {
0. 0 . . . 0 05
0.5
since d1 1, so 0.d1d2 . . . 0.1
=
10k
0.d1d2 . . .
0.d1d2 . . .
0.5
10k = 5 10k = 0.5 10k+1 . X
0.1
9