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

1. Let p 0 =1/2 and f<strong>in</strong>d the first two iterations p 1 ,p 2 of Newton’s method by hand. Mark<br />

the iterates on the graph of f you sketched. Do you th<strong>in</strong>k the iterates will converge to<br />

a zero of f?<br />

2. Let p 0 =0and f<strong>in</strong>d p 1 . What are your conclusions about the convergence of the<br />

iterates?<br />

<strong>Julia</strong> code for Newton’s method<br />

The <strong>Julia</strong> code below is based on Equation (2.6). The variable p<strong>in</strong> <strong>in</strong> the code corresponds to<br />

p n−1 ,andp corresponds to p n . The code overwrites these variables as the iteration cont<strong>in</strong>ues.<br />

Also notice that the code has two functions as <strong>in</strong>puts; f and fprime (the derivative f ′ ).<br />

In [1]: function newton(f::Function,fprime::Function,p<strong>in</strong>,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!