03.03.2014 Views

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

Numerical Methods Course Notes Version 0.1 (UCSD Math 174, Fall ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

54 CHAPTER 4. FINDING ROOTS<br />

Algorithm 4: Algorithm for finding a square root using simple operations.<br />

Input: a number<br />

Output: its square root<br />

sqrt(z)<br />

(1) if z < 0 throw an error.<br />

(2) Let x ← 1, n ← 0.<br />

(3) while n ≤ 50<br />

(4) Let x ← (x + z/x) /2.<br />

(5) Let n ← n + 1.<br />

f(xk+1)<br />

PSfrag replacements<br />

f(x k−1 )<br />

f(x k )<br />

x k<br />

x k−1<br />

x k+1<br />

Figure 4.2: One iteration of the Secant method is shown for some quadratic function f(x). The<br />

secant line through (x k−1 , f(x k−1 )) and (x k , f(x k )) is shown. It happens to be the case that<br />

|f(x k+1 )| is smaller than |f(x k )| , i.e., x k+1 is a better guess than x k .<br />

line at (x k , f(x k )) , which is f ′ (x k ) is approximated by the slope of the secant line passing through<br />

(x k−1 , f(x k−1 )) and (x k , f(x k )) , which is<br />

f(x k ) − f(x k−1 )<br />

x k − x k−1<br />

Thus the iterate x k+1 is the root of this secant line. That is, it is a root to the equation<br />

f(x k ) − f(x k−1 )<br />

x k − x k−1<br />

(x − x k ) = y − f(x k ).

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

Saved successfully!

Ooh no, something went wrong!