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

b) Compute the x-<strong>in</strong>tercept us<strong>in</strong>g each formula when (x 1 ,y 1 )=(1.02, 3.32) and (x 2 ,y 2 )=<br />

(1.31, 4.31). Use three-digit round<strong>in</strong>g arithmetic.<br />

c) Use <strong>Julia</strong> (or a calculator) to compute the x-<strong>in</strong>tercept us<strong>in</strong>g the full-precision of the<br />

device (you can use either one of the formulas). Us<strong>in</strong>g this result, compute the relative<br />

and absolute errors of the answers you gave <strong>in</strong> part (b). Discuss which formula is better<br />

and why.<br />

Exercise 1.3-3: Write two functions <strong>in</strong> <strong>Julia</strong> to compute the b<strong>in</strong>omial coefficient ( )<br />

m<br />

k<br />

us<strong>in</strong>g the follow<strong>in</strong>g formulas:<br />

a) ( )<br />

m<br />

k =<br />

m!<br />

(m! is factorial(m) <strong>in</strong> <strong>Julia</strong>.)<br />

k!(m−k)!<br />

b) ( )<br />

m<br />

k =(<br />

m m−1<br />

m−k+1<br />

)( ) × ... × ( )<br />

k k−1 1<br />

Then, experiment <strong>with</strong> various values for m, k to see which formula causes overflow<br />

first.<br />

Exercise 1.3-4: Polynomials can be evaluated <strong>in</strong> a nested form (also called Horner’s<br />

method) that has two advantages: the nested form has significantly less computations, and<br />

it can reduce roundoff error. For<br />

p(x) =a 0 + a 1 x + a 2 x 2 + ... + a n−1 x n−1 + a n x n<br />

its nested form is<br />

p(x) =a 0 + x(a 1 + x(a 2 + ... + x(a n−1 + x(a n ))...)).<br />

Consider the polynomial p(x) =x 2 +1.1x − 2.8.<br />

a) Compute p(3.5) us<strong>in</strong>g three-digit round<strong>in</strong>g, and three-digit chopp<strong>in</strong>g arithmetic. What<br />

are the absolute errors? (Note that the exact value of p(3.5) is 13.3.)<br />

b) Write x 2 +1.1x − 2.8 <strong>in</strong> nested form by these simple steps:<br />

x 2 +1.1x − 2.8 =(x 2 +1.1x) − 2.8 =(x +1.1)x − 2.8.<br />

Then compute p(3.5) us<strong>in</strong>g three-digit round<strong>in</strong>g and chopp<strong>in</strong>g us<strong>in</strong>g the nested form.<br />

What are the absolute errors? Compare the errors <strong>with</strong> the ones you found <strong>in</strong> (a).

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

Saved successfully!

Ooh no, something went wrong!