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

Geometric <strong>in</strong>terpretation: The slope of the secant l<strong>in</strong>e through the po<strong>in</strong>ts (p n−1 ,f(p n−1 ))<br />

and (p n−2 ,f(p n−2 )) is f(p n−1)−f(p n−2 )<br />

p n−1 −p n−2<br />

.Thex-<strong>in</strong>tercept of the secant l<strong>in</strong>e, which is set to p n ,is<br />

0 − f(p n−1 )<br />

= f(p n−1) − f(p n−2 )<br />

p n−1 − p n−2<br />

⇒ p n = p n−1 − f(p n−1 )<br />

p n − p n−1 p n−1 − p n−2 f(p n−1 ) − f(p n−2 )<br />

which is the recursion of the secant method.<br />

The follow<strong>in</strong>g theorem shows that if the <strong>in</strong>itial guesses are "good", the secant method<br />

has superl<strong>in</strong>ear convergence. A proof can be found <strong>in</strong> Atk<strong>in</strong>son [3].<br />

Theorem 35. Let f ∈ C 2 [a, b] and assume f(p) =0,f ′ (p) ≠0, for p ∈ (a, b). If the <strong>in</strong>itial<br />

guesses p 0 ,p 1 are sufficiently close to p, then the iterates of the secant method converge to p<br />

<strong>with</strong><br />

∣ |p − p n+1 | ∣∣∣<br />

lim<br />

n→∞ |p − p n | = f ′′ r<br />

(p)<br />

1<br />

r 0 2f ′ (p) ∣<br />

where r 0 = √ 5+1<br />

2<br />

≈ 1.62,r 1 = √ 5−1<br />

2<br />

≈ 0.62.<br />

<strong>Julia</strong> code for the secant method<br />

The follow<strong>in</strong>g code is based on Equation (2.12); the recursion for the secant method. The<br />

<strong>in</strong>itial guesses are called pzero and pone <strong>in</strong> the code. The same stopp<strong>in</strong>g criterion as <strong>in</strong><br />

Newton’s method is used. Notice that once a new iterate p is computed, pone is updated as<br />

p, andpzero is updated as pone.<br />

In [1]: function secant(f::Function,pzero,pone,eps,N)<br />

n=1<br />

p=0. # to ensure the value of p carries out of the while loop<br />

while n

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

Saved successfully!

Ooh no, something went wrong!