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 29<br />

the circle, call this number n. Thenn/10000 is approximately the area of the circle. (This<br />

approach is known as the Monte Carlo method.)<br />

Exercise 1.2-3:<br />

Consider the follow<strong>in</strong>g function<br />

f(x, n) =<br />

n∑ i∏<br />

x n−j+1 .<br />

i=1 j=1<br />

a) Compute f(2, 3) by hand.<br />

b) Write a <strong>Julia</strong> code that computes f. Verify f(2, 3) matches your answer above.<br />

1.3 Computer arithmetic<br />

The way computers store numbers and perform computations could surprise the beg<strong>in</strong>ner.<br />

In <strong>Julia</strong> if you type ( √ 3) 2 the result will be 2.9....96, where 9 is repeated 15 times. Here are<br />

two obvious but fundamental differences <strong>in</strong> the way computers do arithmetic:<br />

• only f<strong>in</strong>itely many numbers can be represented <strong>in</strong> a computer;<br />

• a number represented <strong>in</strong> a computer can only have f<strong>in</strong>itely many digits.<br />

Therefore the numbers that can be represented <strong>in</strong> a computer exactly is only a subset of<br />

rational numbers. Anytime the computer performs an operation whose outcome is not a<br />

number that can be represented exactly <strong>in</strong> the computer, an approximation will replace the<br />

exact number. This is called the roundoff error: error produced when a computer is used to<br />

perform real number calculations.<br />

Float<strong>in</strong>g-po<strong>in</strong>t representation of real numbers<br />

Here is a general model for represent<strong>in</strong>g real numbers <strong>in</strong> a computer:<br />

x = s(.a 1 a 2 ...a t ) β × β e (1.1)

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

Saved successfully!

Ooh no, something went wrong!