Newton’s Method D. P. Morstad, University of North Dakota Objectives of Assignment 1. Learning to use Newton's method to solve equations. I. Introduction How would you try to solve equations such as x 2 − 3x + 1 = sin x , or x 5 − 0.05 = 0 ? The simple algebraic methods you’ve always relied on are inadequate for equations like these. Two very bright fellows, Sir Isaac Newton and Joseph Raphson, came up with a clever way to generate solutions for such equations. The solutions are not exact, but they can be made as precise as you want them to be. The Newton-Raphson Method of solving equations, often called Newton’s Method, requires you to make a guess at what the solution is, and then it uses your guess and tangent lines to get successively closer and closer to the solution. II. Four Steps to Solve f(x) = 0 Using Newton's Method è First, make an educated guess what the solution is. Call your educated guess x guess . è Second, find the line tangent to f(x) at x = x guess . è Third, follow that tangent line to the x–axis to find where it intersects the x–axis . è Fourth, use the point where the tangent line intersects the x–axis as an improved guess. Then repeat the entire process using this improved guess as x guess . Repeat the process over and over again until the desired degree of accuracy is achieved. 23 An algorithm such as this where you start with some seed value such as x guess , perform computations on the seed value, get an output value, and then do the entire procedure over again using the output as a new seed value, is called an iterative process. Newton’s Method is an iterative process. III. An Example With an Explanation In this example, X(PLORE) will help you make the educated guess and it will help you understand why Newton’s Method works. You will have to replicate all of this to solve other problems. Do not just do each step – try to understand why and how you are doing each step. Example: Solve the equation x 5 − 0. 05 = 0 . (Notice the solution must be 5 0.05 ) Before we start the problem, notice that solving the equation is the same as graphically determining where the function f ( x ) = x 5 − 0.05 intersects the x–axis. We will try to find the point of intersection, so have X(PLORE) graph f(x). It should look like Figure 1. below. 1 1 f( x) 0 1 1 1 0 1 1 x 1 Figure 1. Graph of f ( x ) = x 5 − 0.05 FIRST, MAKE A GUESS: From the graph, it is easy to see that the function crosses through the x–axis between x = 0 and x = 1. Let's guess that it passes through the x– axis at x = 0.9. You can tell that this is not a perfect guess. 0.55 might have been closer, but 0.9 will best help demonstrate Newton’s Method. SECOND, FIND THE TANGENT LINE: Figure 2 below shows you how high above the x–axis the graph is at x = 0.9. Have X(PLORE) graph this vertical line by using the command “line(0.9, 0, 0.9, f(0.9))”. In general, this command would be “line(x guess, 0, x guess, f(x guess))”, after you typed in and entered x guess = 0.9. 24 1 1 f( x) 0 t 1 1 1 0 1 1 x, g( t ) 1 Figure 2. Where the function is when x = 0.9 The goal of this second step is to find the tangent line at (0.9, f(0.9)).The equation of this tangent line is y − f (09 . ) = f ' (09 . ) ⋅ ( x − 09 . ). Notice that this is just the equationy − y1 = m( x − x1 ). In general, it is: y − f ( x guess ) = f '( x guess ) ⋅ ( x − x guess ). This tangent line is included in Figure 3. You should make X(PLORE) graph this line by solving the equation for y and then calling it some function like tanline(x). That is, Tanline( x ) = f ′( x guess ) ⋅ ( x − x guess ) + f ( x guess ) . 1 1 f( x) t 0 h( v ) 1 1 1 0 1 1 x, g( t ) , v 1 Figure 3. The tangent line gets closer to the function's intersection with the x–axis. THIRD, FOLLOW THAT TANGENT LINE: The tangent line hits the x-axis closer to the actual solution than our guess does, so lets find where the tangent line intersects the xaxis. To do this, just use the equation for the tangent line given above, and then put in 0 for y (because the x–intercept always has 0 for the y–coordinate). 25 The equation for the tangent line is: y − f ( x guess ) = f '( x guess ) ⋅ ( x − x guess ), which becomes: 0 − f ( x guess ) = f ' ( x guess ) ⋅ ( x − x guess ) . Putting in 0.9, the equation becomes: 0 − f ( 0.9 ) = f '( 0. 9) ⋅ ( x − 0. 9) . Solving this equation for x will give the x–intercept of the tangent line: x= 0.9 ⋅ f '( 0.9 ) − f ( 0.9 ) , f '( 0. 9) Eq. 1 or x = 0.73524158. FOURTH, DO IT AGAIN: Since this value of x is closer to the solution (the function’s xintercept) than our original guess was, let’s just do it all over again with x guess = 0.73524158 . Graphically this is shown in Figure 4 below. 1 0 1 1 0 1 Figure 4. The second iteration of Newton's method yields an even closer approximation of the solution. Numerically, simply put 0.73524158 into Eq. 1 instead of 0.9. Or, with X(PLORE), set x guess = 0.73524158 . This yields: x= 0.73524158 ⋅ f '( 0. 73524158 ) − f ( 0.73524158 ) f '( 0.73524158 ) or 26 x = 0.62241324. This procedure can be repeated again using x guess = 0.62241324 in order to reach an even closer estimate of the solution. You can keep repeating this procedure until you’ve reached any desired level of accuracy. IV. A Summary of Newton's Method and Using X(PLORE) . 1. Graphically approximate the solution to f ( x ) = 0. Call this approximation x guess . 2. Graph and find where the line tangent to f(x) intersects the x–axis. Evaluate the x x ⋅ f '( x guess ) − f ( x guess ) coordinate of the point of intersection using x new = guess . f ' ( x guess ) 3. Use x new for the next value of x guess , then graph and evaluate again. 4. Repeat until the desired level of accuracy is achieved. The following lines will make X(PLORE) do everything for you. Type in the following line and replace only the italicized words . It behooves you to figure out and understand this process - simply mindlessly making X(PLORE) do everything for you is wasting your time. f(x) = type your function here in place of these italicized words derivf(x) = type the derivative of your function here window(xleft, xright, ybottom, ytop) graph(f(x), x) xguess = your first guess line(xguess, 0, xguess, f(xguess)) tanline(x) = derivf(xguess)¬(x – xguess) + f(xguess) graph(tanline(x), x) xnew = (xguess¬ derivf(xguess) – f(xguess))/derivf(xguess) xguess = xnew You may reuse the above lines over and over again by changing the function, derivative, window, and first guess. 27 IV. Example Using X(PLORE) Solve x 2 − 3x + 1 = sin x to six decimal places. Solution: First rewrite it as x 2 − 3x + 1 − sin x = 0 . Then use f ( x ) = x 2 − 3 x + 1 − sin x and try to find the solution to f(x) = 0. Give X(PLORE) both the function and the derivative as shown in the box on the previous page. Next use window(–6, 6, –6, 6) and graph f(x). Notice that the function intersects the x–axis twice. This mean there are two solutions to the equation. It appears that one intersection is around x = 4, so set x guess = 4. Have X(PLORE) draw the line from the x-axis to the function by pressing E on the appropriate line that you typed in. Pressing E on the next line will make X(PLORE) determine the tangent line as a function of x. Pressing E on the following line graphs the tangent line. Now, instead of using the crosshairs to find where the tangent line intersects the x-axis, have X(PLORE) find it algebraically by pressing E the next line. X(PLORE) calls it x new. It should be 2.981754. Now tell X(PLORE) to let x guess = x new so you won’t have to retype anything. Go back up to the line which graphed the vertical line and press the E key to repeat the process. Continually repeating this process gives no change after reaching x = 2.770058. This is one solution to six decimal places. To find the other solution, go back to the graph and get an approximation of the leftmost root. Put this in for x guess at the beginning and repeat the process. This solution is x = 0.268881 to six decimal places. 28 V. Practice Exercises Use X(PLORE) and Newton's method to solve each of the following to six decimal places. 1. Find all solutions to cos x = x 2 . 2. Find 3. Find all real solutions to x 5 − 3x 4 + x 3 + 5 x 2 − 6x + 1 = 0. 4. Find all real solutions to x 4 + x 3 + 41 = 22 x 2 + 2 x. 5 Find all solutions to csc( x ) = x 2 on [ 0, π]. 6. Find all solutions to tan x = sec x on [ −π, π]. 7. Find all solutions to 10 5 . (hint: the first example found 5 0.05 ) 1 − x 2 = sin x on ( −11 , ). Answers: 1. –0.824132, 0.824132; 2. –1.174619, 1.174619; 3. –1.388008, 0.200888, 1.872424; 4. –4.995156, –1.432340, 1.435476, 3.992020; 5. 1.068224, 3.032645; 6. π2 =1.570796; 7. 0.739085 29