1
4+x–2
1.19 Consider the function f ( x ) = ------------------------- .
x
(a) Use the decimal format with six significant digits (apply rounding at each step) to calculate (using a
calculator) f ( x ) for x = 0.001 .
(b) Use MATLAB (format long) to calculate the value of f ( x ) . Consider this to be the true value, and
calculate the true relative error due to rounding in the value of f ( x ) that was obtained in part (a).
4+x+2
(c) Multiply f ( x ) by ------------------------- to obtain a form of f ( x ) that is less prone to rounding errors. With the
4+x+2
new form, use the decimal format with six significant digits (apply rounding at each step) to calculate
(using a calculator) f ( x ) for x = 0.001 . Compare the value with the values in parts (a) and (b).
Solution
2.00025 – 2 0.00025
(a) To six significant figures, f ( x ) = ---------------------------- = ------------------- = 0.25
0.001 0.001
(b) Using the format long in MATLAB:
>> format long
>> x=0.001;
>> f=(sqrt(4+x)-2)/x
f =
0.249984376953005
The true relative error, according to Eq. (1.17) is:
0.249984376953005 – 0.25 = 0.000062496
TrueRelativeError = -----------------------------------------------------------------
-
0.249984376953005
4+x+2
(c) Multiplying f ( x ) by ------------------------- yields:
4+x+2
f ( x ) = ------------------------- ------------------------- = -------------------------
4+x–2 4+x+2 1
x 4 + x + 2 4+x+2
Using the values to 6 significant figures from part (a),
1 1
f ( 0.001 ) = --------------------------- = ---------------------------- = 0.249984
4.001 + 2 2.00025 +2
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
2
The true relative error is now:
0.249984376953005 – 0.249984 = 1.504 × 10 – 6
TrueRelativeError = -----------------------------------------------------------------------------
-
0.249984376953005
Clearly, the above form for f ( x ) is more accurate than the form used in part (a) and the form given in the
problem statement.
Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.