06.09.2021 Views

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

First Semester in Numerical Analysis with Julia, 2020a

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1. INTRODUCTION 44<br />

Next will use four-digit arithmetic <strong>with</strong> round<strong>in</strong>g to compute the roots:<br />

fl( √ 117) = 10.82<br />

(<br />

fl(fl(11.0) + fl( √ ) ( ) ( )<br />

117)) fl(11.0+10.82) 21.82<br />

fl(r 1 )=fl<br />

= fl<br />

= fl =10.91<br />

fl(2.0)<br />

2.0<br />

2.0<br />

(<br />

fl(fl(11.0) − fl( √ ) ( ) ( )<br />

117)) fl(11.0 − 10.82) 0.18<br />

fl(r 2 )=fl<br />

= fl<br />

= fl =0.09.<br />

fl(2.0)<br />

2.0<br />

2.0<br />

The relative errors are:<br />

rel error <strong>in</strong> r 1 =<br />

10.90832691 − 10.91<br />

∣ 10.90832691 ∣ =1.5 × 10−4<br />

rel error <strong>in</strong> r 2 =<br />

0.09167308680 − 0.09<br />

∣ 0.09167308680 ∣ =1.8 × 10−2 .<br />

Notice the larger relative error <strong>in</strong> r 2 compared to that of r 1 , about a factor of 100, whichis<br />

due to cancellation of lead<strong>in</strong>g digits when we compute 11.0 − 10.82.<br />

One way to fix this problem is to rewrite the offend<strong>in</strong>g expression by rationaliz<strong>in</strong>g the<br />

numerator:<br />

r 2 = 11.0 − √ 117<br />

2<br />

( ) √<br />

1 11.0 − 117<br />

=<br />

2 11.0+ √ 117<br />

If we use this formula to compute r 2 we get:<br />

(<br />

)<br />

2.0<br />

fl(r 2 )=fl<br />

fl(11.0+fl( √ 117))<br />

(<br />

11.0+ √ ) ( 1<br />

117 =<br />

2)<br />

4<br />

11.0+ √ 117 = 2<br />

11.0+ √ 117 .<br />

( ) 2.0<br />

= fl =0.09166.<br />

21.82<br />

The new relative error <strong>in</strong> r 2 is:<br />

( )<br />

0.09167308680 − 0.09166<br />

rel error <strong>in</strong> r 2 =<br />

=1.4 × 10 −4 ,<br />

0.09167308680<br />

an improvement about a factor of 100, even though <strong>in</strong> the new way of comput<strong>in</strong>g r 2 there<br />

are two operations where round<strong>in</strong>g error happens <strong>in</strong>stead of one.<br />

Example 20. The simple procedure of add<strong>in</strong>g numbers, even if they do not have mixed signs,<br />

can accumulate large errors due to round<strong>in</strong>g or chopp<strong>in</strong>g. Several sophisticated algorithms<br />

to add large lists of numbers <strong>with</strong> accumulated error smaller than straightforward addition<br />

exist <strong>in</strong> the literature (see, for example, Higham [11]).<br />

For a simple example, consider us<strong>in</strong>g four-digit arithmetic <strong>with</strong> round<strong>in</strong>g, and comput<strong>in</strong>g

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!