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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 1. INTRODUCTION 38<br />

Chopp<strong>in</strong>g & Round<strong>in</strong>g<br />

Let x be a real number <strong>with</strong> more digits the computer can handle: x =0.d 1 d 2 ...d k d k+1 ...×<br />

10 n . How will the computer represent x? Let’s use the notation fl(x) for the float<strong>in</strong>g-po<strong>in</strong>t<br />

representation of x. There are two choices, chopp<strong>in</strong>g and round<strong>in</strong>g:<br />

• In chopp<strong>in</strong>g, we simply take the first k digits and ignore the rest: fl(x) =0.d 1 d 2 ...d k .<br />

• In round<strong>in</strong>g, if d k+1 ≥ 5 we add 1 to d k to obta<strong>in</strong> fl(x). If d k+1 < 5, then we simply<br />

do as <strong>in</strong> chopp<strong>in</strong>g.<br />

Example 11. F<strong>in</strong>d 5-digit (k =5) chopp<strong>in</strong>g and round<strong>in</strong>g values of the numbers below:<br />

• π =0.314159265... × 10 1<br />

Chopp<strong>in</strong>g gives fl(π) =0.31415 × 10 1 and round<strong>in</strong>g gives fl(π) =0.31416 × 10 1 .<br />

• 0.0001234567<br />

We need to write the number <strong>in</strong> the normalized representation first as 0.1234567×10 −3 .<br />

Now chopp<strong>in</strong>g gives 0.12345 × 10 −3 and round<strong>in</strong>g gives 0.12346 × 10 −3 .<br />

Absolute and relative error<br />

S<strong>in</strong>ce computers only give approximations to real numbers, we need to be clear on how we<br />

measure the error of an approximation.<br />

Def<strong>in</strong>ition 12. Suppose x ∗ is an approximation to x.<br />

• |x ∗ − x| is called the absolute error<br />

• |x∗ −x|<br />

|x|<br />

is called the relative error (x ≠0)<br />

Relative error usually is a better choice of measure, and we need to understand why.<br />

Example 13. F<strong>in</strong>d absolute and relative errors of<br />

1. x =0.20 × 10 1 ,x ∗ =0.21 × 10 1<br />

2. x =0.20 × 10 −2 ,x ∗ =0.21 × 10 −2<br />

3. x =0.20 × 10 5 ,x ∗ =0.21 × 10 5<br />

Notice how the only difference <strong>in</strong> the three cases is the exponent of the numbers. The<br />

absolute errors are: 0.01 × 10 , 0.01 × 10 −2 , 0.01 × 10 5 . The absolute errors are different<br />

s<strong>in</strong>ce the exponents are different. However, the relative error <strong>in</strong> each case is the same: 0.05.

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

Saved successfully!

Ooh no, something went wrong!