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 2. SOLUTIONS OF EQUATIONS: ROOT-FINDING 59<br />

We have, from the proof of the previous theorem (see (2.3)) : |p n −p| ≤ 1 (b−a). Therefore,<br />

2 n<br />

we can make |p n − p| ≤10 −L , by choos<strong>in</strong>g n large enough so that the upper bound 1 (b − a)<br />

2 n<br />

is less than 10 −L :<br />

( )<br />

1<br />

b − a<br />

2 (b − a) ≤ n 10−L ⇒ n ≥ log 2 .<br />

10 −L<br />

Example 30. Determ<strong>in</strong>e the number of iterations necessary to solve f(x) =x 5 +2x 3 − 5x −<br />

2=0<strong>with</strong> accuracy 10 −4 ,a=0,b=2.<br />

Solution. S<strong>in</strong>ce n ≥ log 2<br />

( 2<br />

10 −4 )<br />

=4log2 10+1=14.3, the number of required iterations is<br />

15.<br />

Exercise 2.2-1: F<strong>in</strong>d the root of f(x) =x 3 +4x 2 − 10 us<strong>in</strong>g the bisection method,<br />

<strong>with</strong> the follow<strong>in</strong>g specifications:<br />

a) Modify the <strong>Julia</strong> code for the bisection method so that the only stopp<strong>in</strong>g criterion<br />

is whether f(p) =0(remove the other criterion from the code). Also, add a pr<strong>in</strong>t<br />

statement to the code, so that every time a new p is computed, <strong>Julia</strong> pr<strong>in</strong>ts the value<br />

of p and the iteration number.<br />

b) F<strong>in</strong>d the number of iterations N necessary to obta<strong>in</strong> an accuracy of 10 −4 for the root,<br />

us<strong>in</strong>g the theoretical results of Section 2.2. (The function f(x) has one real root <strong>in</strong><br />

(1, 2), so set a =1,b=2.)<br />

c) Run the code us<strong>in</strong>g the value for N obta<strong>in</strong>ed <strong>in</strong> part (b) to compute p 1 ,p 2 , ..., p N (set<br />

a =1,b=2<strong>in</strong> the modified <strong>Julia</strong> code).<br />

d) The actual root, correct to six digits, is p =1.36523. F<strong>in</strong>d the absolute error when p N<br />

is used to approximate the actual root, that is, f<strong>in</strong>d |p − p N |. Compare this error, <strong>with</strong><br />

the upper bound for the error used <strong>in</strong> part (b).<br />

Exercise 2.2-2: F<strong>in</strong>d an approximation to 25 1/3 correct to <strong>with</strong><strong>in</strong> 10 −5 us<strong>in</strong>g the bisection<br />

algorithm, follow<strong>in</strong>g the steps below:<br />

a) <strong>First</strong> express the problem as f(x) =0<strong>with</strong> p =25 1/3 the root.<br />

b) F<strong>in</strong>d an <strong>in</strong>terval (a, b) that conta<strong>in</strong>s the root, us<strong>in</strong>g Intermediate Value Theorem.<br />

c) Determ<strong>in</strong>e, analytically, the number of iterates necessary to obta<strong>in</strong> the accuracy of<br />

10 −5 .

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

Saved successfully!

Ooh no, something went wrong!