HP 15c User Manual

Page 149

Advertising
background image

Appendix: Accuracy of Numerical Calculations

149

Regarding the first misconception, example 1 would behave in the same perverse way if it
suffered only one rounding error, the one that produces R(x) = 1 or 0.9999999999, in error by
less than one unit in its last (10th) significant digit.

Regarding the second misconception, cancellation is what happens when two nearly equal
numbers are subtracted. For example, calculating

2

/

)

cos

1

(

)

(

x

x

x

c

in Radians mode for small values of x is hazardous because of cancellation. Using x =
1.2×10

-5

and rounding results to 10 digits

cos x = 0.9999999999

and

1 - cos x = 0.0000000001

with cancellation leaving maybe one significant digit in the numerator. Also

x

2

= 1.44×10

-10

.

Then

C(x) = 0.6944.

This calculated value is wrong because

2

1

)

(

0

x

c

for all x ≠ 0. To avoid numerical

cancellation, exploit the trigonometric identity

 

2

sin

2

1

cos

2

x

x

to cancel the 1 exactly and

obtain a better formula

 

.

sin

2

1

)

(

2

2

2





x

x

x

c

When this latter expression is evaluated (in Radians mode) at x = 1.2×10

-5

, the computed

result C(x) = 0.5 is correct to 10 significant digits. This example, while explaining the
meaning of the word "cancellation," suggests that it is always a bad thing. That is another
misconception to be dispatched later. For the present, recall that example 1 contains no
subtraction, therefore no cancellation, and is still devastated by its rounding error. In this
respect example 1 is counterintuitive, a little bit scary. Nowhere in it can we find one or two
arithmetic operations to blame for the catastrophe; no small rearrangement will set
everything right as happened for c(x). Alas, example 1 is not an isolated example. As
computers and calculators grow in power, so do instances of insidious error growth become
more common.

To help you recognize error growth and cope with it is the ultimate goal of this appendix. We
shall start with the simplest kinds of errors and work our way up gradually to the subtle
errors that can afflict the sophisticated computations possible on the HP-15C.

Advertising