MT414.001 ASSIGNMENT 1 DUE 29 JANUARY 2009 1.1.1 Use four iteations of bisection with the initial bracket [0.5, 1] to approximate the sole positive root of cos(x) − x = 0. Repeat with inverse linear interpolation, using the same initial bracket; note the one-sided approach to the solution. Solution. Using bisection gives a sequence of Iterate Value Correct digits x1 0.75 1 x2 0.625 0 x3 0.6875 0 x4 0.71875 1 Four iterations of inverse linear iteration gives a sequence of Iterate Value Correct digits x1 0.725481587063930 1 x2 0.738398620137093 2 x3 0.739050731114720 4 x4 0.739083409893471 5 After four iterations, inverse linear iteration looks to have about five digits correct, while bisection has just one. 1.1.5 Use inverse linear interpolation with initial bracket [0.25, 2] to approximate a zero of f (x) = x13 − 10 to three decimal places. Repeat with bisection. Comment. Solution. Inverse linear iteration takes about 29 iterations to get three correct digits (it arrives at 0.464882748431588). Bisection, on the other hand only takes 11 iterations to get to within three correct digits. We can see this plainly by noting that −3 w ∗ 2−k < 10−3 occurs when k > − log2 10w . With w = 2 − 0.25 = 1.75, we know that we’ll be within 10−3 of the true solution after at most 11 iterations. 1.1.7 Using bisection starting from the initial bracket [0, 2], estimate the number of iterations that would be required to find a root of ex − 4x = 0 to four decimal place accuracy. How many iterations are needed until the midpoint of the interval is actually correct to four decimal places? Solution. In order to have four digits correct, we mean the error must be bounded above by 10−4 . Of course, this doesn’t actually mean that four digits will be exactly correct; we may be off by the one in the last digit. For bisection, we know that each iteration reduces the width of the interval by a factor of two, and so we want to find the smallest N to satisfy 10−4 ≥ w2−N 1 where w is the width of the initial interval. Thus, solving for N we obtain log2 (w) + 4 log2 (10) ≤ N. In this case, w = 2, and so we require N ≥ 1 + 4 log2 (10) ≈ 14.3. Thus after 15 steps, we expect that we will have four digits correct. For this problem, however, we actually obtain four correct digits at the tenth iteration by sheer luck, even though by this point we should have only had about 3 digits correct. 1.1.9 (a) Justify the following equations dominating inverse linear interpolation: x 1 − x0 x 1 − x0 x= y + x1 − f (x1 ) f (x1 ) − f (x0 ) f (x1 ) − f (x0 ) and x2 = x1 − f (x1 ) x1 − x0 f (x1 ) − f (x0 ) by finding the equation of a line x = my + b between the two points (x0 , f (x0 ) and (x1 , f (x1 ) and then finding its x-intercept. Solution. Consider the two points on the graph of the function (x0 , f (x0 )) and (x1 , f (x1 )). An equation of a line through these points is y − f (x1 ) = f (x1 ) − f (x0 ) (x − x1 ). x1 − x0 Solving this equation for x gives x= x1 − x0 (y − f (x1 )) + x1 f (x1 ) − f (x0 ) which can be readily rearranged to x1 − x 0 x1 − x0 x= y + x1 − f (x1 ) . f (x1 ) − f (x0 ) f (x1 ) − f (x0 ) Now, the next iterate is the x-intercept of this line which is obtained when y = 0. Thus the next iterate is x2 = x1 − x1 − x0 f (x1 ). f (x1 ) − f (x0 ) (b) What happens if inverse linear interpolation is applied to a linear function f (x) = ax + b? Is the same true for bisection? 2 Solution. Note that the root for a linear function is x = −b . Suppose that a [x0 , x1 ] forms a bracket. The next iterate x2 is given by x1 − x0 f (x1 ) x 2 = x1 − f (x1 ) − f (x0 ) x1 − x0 = x1 − (ax1 + b) (ax1 + b) − (ax0 + b) x1 − x0 = x1 − (ax1 + b) a(x1 − x0 ) 1 = x1 − (ax1 + b) a −b = . a Thus inverse linear iteration converges in exactly one iteration for a linear function. 1.2.5 Use Newton’s method to approximate a zero of f (x) = places. 1 x3 − 10 to three decimal Solution. Use the code on the webpage http://www2.bc.edu/~quillen/mt414/prog/newtonit.m −1 with a tolerance of 10−3 . Note that the exact answer is 10 3 . As the cube root of 10 is slightly bigger than 2, we know that it’s reciprocal must be slightly less than 0.5, making 0.5 a good initial guess. With an initial guess of x0 = 0.5, this code converges in about three iterations to 0.464158792772989. The correct answer is approximately 0.464158883361278, and so our approximation gets about six correct digits, which is twice as many as we requested. 1.2.13 Use the secant method to approximate a zero of f (x) = 1 x3 − 10 to six decimal places. Solution. As above, use the code on the webpage http://www2.bc.edu/~quillen/mt414/prog/secant.m but this time with a tolerance of 10−6 . With initial guesses of x0 = 0.4, and x1 = 0.5, the code converges in about five iterations to 0.464158883245481. The correct answer is approximately 0.464158883361278, and so our approximation gets about nine correct digits, which is half again as many digits as we requested. 1.3.4 (a) An early method for performing division b/a of computers was to apply Newton’s method to f (x) = x1 − a to find 1/a and then multiply it by b. Show that Newton’s method for f (x) requires only multiplication and subtraction, and that it converges for all x0 ∈ (0, a1 ]. (Hint: Plot Nf (x) and sketch a few iterates.) What happens if x0 >> 1/a? Solution. Recall that Newton’s method is a fixed-point iteration with Nf (x) = x − ff0(x) as the iteration function. For f (x) = x1 − a, we have f 0 (x) = −1 and (x) x2 3 therefore we have Nf (x) = x − 1 x −a −1 x2 = x + x − ax2 = 2x − ax2 . To apply Newton’s method then, all we need to be able to do is multiply and add. Now, we mustshow that Newton’s method will converge to a1 if we start with any point in 0, a1 . By the fixed-point theorem, Newton’s method converges when |Nf0 (x)| < 1. In this case, Nf (x)0 = 2(1 − ax), and thus the method converges 1 3 . To show what we desire, whenever we begin with a point in the interval 2a , 2a all we need to do is to determine what happens when we begin with a point in 1 the interval 0, 2a . 1 Suppose x ∈ 0, 2a , and write x = ap for p ∈ 0, 12 . Then, Nf (x) = (2 − ax)x = (2 − p) p a For p as above, we can establish 3 p p 1 ≤ (2 − p) < . 2 a a a Now, as the sequence n o∞ 2k 3 converges to zero, it follows that there exists some k=0 k 0, 32 N such that for any p > < p for all k > N . Based on the bound above it follows that after N steps of Newton’s method, we have entered the interval of convergence. Thus, for all x ∈ 0, a1 , Newton’s method converges. Now, one can apply a similar argument to show that if the initial point is much larger than a1 , then Newton’s method must diverge. To be very specific, when the initial point is greater than a2 , Newton’s method must diverge. Also, when the initial point is exactly a2 Newton’s method converges (falsely) to 0. (b) Use this method with a = 3 to approximate 1/3. Use initial guesses x0 = 0.5, 1, 2, 4. In each case make a table showing only those leading digits in your answer that agree with the solution. What can you say about the rapidity of convergence of Newton’s method in this case? (This method is still commonly used on high-performance machines to implement quadruple precision division.) Solution. Note that based on our observations above, we see that with any initial guess larger than 32 , the method must diverge. We see convergence only for the initial guess of x0 = 0.5. In this case, we have iterates of 4 Iterate x0 x1 x2 x3 x4 x5 x6 Value 0.5 0.25 0.3125 0.33203125 0.333328247070312 0.333333333255723 0.333333333333333 1.3.11 (a) The Fixed Point Theorem is a special case of a more general result known as the Contraction Mapping Theorem. If D is a closed subset of Rn and T : D → D, then T is said to be a contraction (or to be contractive) on D if there is an s, 0 < s < 1, such that |T (x) − T (y)| ≤ s|x − y| for all x, y ∈ D. (We interpret | · | as a vector norm if necessary.) The constant s is called the contractivity factor. Show that if a function meets the hypotheses of the Fixed Point Theorem, then it is a contraction on some D ⊂ R. What is the contractivity factor s? Solution. Proof. Suppose T : [a, b] → [a, b] as in the Fixed-point theorem. That is, T is continuous on [a, b] and differentiable on (a, b) such that |T 0 (x)| ≤ λ with λ : 0 < λ < 1. We must show that T is a contraction. Now, as T is differentiable in (a, b) for any x, y ∈ [a, b] there exists θ ∈ (x, y) such that T (x) − T (y) = T 0 (θ)(x − y). Therefore |T (x) − T (y)| = |T 0 (θ)||x − y| ≤ λ |x − y| for any x, y ∈ [a, b]. That is, T is a contraction with contractivity factor λ. (b) Prove that a contraction T must be continuous. Solution. Proof. Suppose T is a contraction with contractivity factor s and let ε > 0. Choose δ = sε and note that |T (x) − T (y)| ≤ s|x − y| < sδ = ε whenever |x − y| < δ. Therefore, by definition, T is continuous. (c) The Contraction Mapping Theorem states that every contraction mapping has a unique fixed point on its domain D, often called an invariant set or attractor in this context. Prove the Contraction Mapping Theorem. Solution. Note that the full proof of this theorem is out of the scope of this class, so what follows is what you were expected to do. Proof. Suppose T is a contraction on [a, b], and consider G(x) = x − T (x). Now, G(a) ≤ 0 with equality if T (a) = a, in which case T has a fixed point. Assume, then, that G(a) < 0. Similarly, we assume that G(b) > 0 must be the case. Now, then as, T is a contraction and therefore continuous, it follows by the intermediate value theorem, there exists x∗ such that G(x∗ ) = 0 and so T (x∗ ) = x∗ establishing the existence of a fixed point. 5 To show that the fixed point is unique, assume that there are two distinct fixed points, say p and q. Then |p − q| = |T (p) − T (q)| ≤ s|p − q| < |p − q| since T is a contraction and s < 1. This is a contradiction, and therefore the fixed point must be unique. For your edification, here is a proof of the Contraction Mapping Theorem as stated above: Proof. Suppose T is a contraction on D, a closed subset of Rn . Define a sequence {xk }∞ k=0 by choosing some arbitrary x0 ∈ D and setting xk+1 = T (xk ) for all k ≥ 0. Now then |xk+1 − xk | = |T (xk ) − T (xk−1 )| ≤ s|xk − xk−1 |. Inductively, then |xk+1 − xk | ≤ sk |x1 − x0 | for k ≥ 1. Now, consider j, k ≥ 1, and additionally assume without loss of generality that j > k. We have |xj − xk | = |xj − xj−1 + xj−1 − · · · − xk+1 + xk+1 − xk | ≤ |xj − xj−1 | + |xj−1 − xj−2 | + · · · + |xk+1 − xk | ≤ sj−1 |x1 − x0 | + sj−2 |x1 − x0 | + · · · + sk |x1 − x0 | = sk |x1 − x0 | sj−1−k + · · · + s2 + s + 1 ∞ X k ≤ s |x1 − x0 | si i=0 = sk |x1 − x0 | 1−s since s < 1. Therefore, for any ε > 0 there exists K > 0 such that for all j, k ≥ K, we have |xj − xk | ≤ sk |x1 − x0 | < ε. 1−s Thus the sequence {xk }∞ k=0 is a Cauchy sequence, and all Cauchy sequences in Rn converge. Thus there exists x∗ such that xk → x∗ as k → ∞. Since D is ∗ closed, and {xk }∞ k=0 ⊆ D, it follows that x ∈ D. ∗ Now, limk→∞ T (xk ) = limk→∞ xk+1 = x . Also, as T is continuous, limk→∞ T (xk ) = T (x∗ ). Thus T (x∗ ) = x∗ , establishing the existence of the fixed point. To establish uniqueness, we do the same as above. (d) Show that the function on R2 defined by T (x, y) → 12 x + 1, 12 y is a contraction. What is its contractivity factor? Find its invariant set analytically, and then verify that fixed point iteration converges to that fixed point. 6 Solution. Consider (x1 , y1 ), (x2 , y2 ) ∈ R2 and note that 1 1 1 1 x2 + 1, y2 |T (x1 , y1 ) − T (x2 , y2 )| = x1 + 1, y1 − 2 2 2 2 1 1 = (x1 − x2 ), (y1 − y2 ) 2 2 1 = |(x1 − x2 , y1 − y2 )| 2 1 = |(x1 , y1 ) − (x2 , y2 )| 2 This shows that T is a contraction on all of R2 with contractivity factor 21 . The fixed point satisfies 1 1 (x, y) = T (x, y) = x + 1, y . 2 2 That is, x = 12 x + 1 which implies that x = 2. Also, y = 12 y which implies that y = 0. Thus the fixed point of T is the point (2, 0). Let’s establish that the fixed point iteration converges to this fixed point. Choose an arbitrary (x0 , y0 ) ∈ Rn . Note that 1 1 (x1 , y1 ) = T (x0 , y0 ) = x0 + 1, y0 2 2 and thus 1 1 (x2 , y2 ) = T (x1 , y1 ) = x1 + 1, y1 2 2 1 1 1 x0 + + 1, y0 = 4 2 4 It is not hard to establish that ! k X 1 1 1 x0 + , y . (xk , yk ) = j 2k 0 2k 2 j=0 P∞ 1 Thus xk → j=0 2j = 2 and yk → 0 and so the fixed point iteration converges to the fixed point. 7