Newton s method Introduction In this laboratory we will become familiar with Newton s method for attaining successive approximations to the zero of a function Newton s method is also known as the Newton Raphson method The While and For loop statements for the repetitive execution of code as well as the Print command will be used Successive approximations will also be illustrated graphically Newton s method is a technique for approximating the zeros of a function It is based on the observation that in most cases if we make a fairly good initial guess say x0 to the zero of a function f then the x intercept of the tangent line to the graph of f at x0 f x0 called x1 is a better estimate of the zero than was x0 Repeating this process n times we find that the n 1 st approximation is given by xn 1 xn f xn f xn Examples Example 1 is based on prior Math 149 Maple laboratories Example 2 was created in Mathematica for Math 151 Example 1 Find all numbers x in the interval 0 1 for which cos 3px 2 2 x To determine the number of solutions to this problem we plot a graph of the functions F x cos 3px 2 2 and G x x for 0 x 1 Then the solutions to this problem are all the values of x at which F x G x In 1 funcF x Cos 3 Pi x 2 2 funcG x x It is also evident that the solutions to our problem are the zeros of the function f x G x F x We plot a graph of the functions f F and G to illustrate our remark 2 Newtons method nb In 3 f x funcG x funcF x Plot funcF x funcG x f x x 0 1 PlotStyle Red Blue Green 1 0 0 5 Out 4 0 2 0 4 0 6 0 8 1 0 0 5 1 0 We can see that there are three points of intersection one near 0 25 one near 0 5 and one near 0 75 In order to estimate these three zeros of f in the interval 0 1 using Newton s method we begin by defining a function newton which will be used to compute the successive approximations This function corresponds to the formula for the Newton iteration mentioned in the Introduction In 5 newton x x f x f x If we iterate with this function then the iteration does not remember all intermediate values xn but instead constantly overwrites the value of x as soon as a better approximate solution has been found see the line xn newton xn in the code below Note that if you insist on using the D operator for the definition of the derivative term in the newton function then you need to separate the two steps of differentiation and evaluation i e you would have to define newton like this newton x t f t D f t t t x The following code iterates Newton s method until we have found an x for which f x is less than 10 10 in absolute value see the While statement below The commands PaddedForm and NumberForm are used to format the computed numbers nicely In 6 xn 0 25 our initial guess Print x0 PaddedForm xn 12 12 f x0 NumberForm f xn 12 k 0 a counter While Abs f xn 10 10 xn newton xn k k 1 Print x k PaddedForm xn 12 12 f x k NumberForm f xn 12 x0 0 250000000000 f x0 0 103553390593 x1 0 226096603561 f x1 0 00826202284178 x2 0 227751553321 f x2 0 0000325802639608 x3 0 227758131503 f x3 5 23180249123 10 10 x4 0 227758131609 f x4 1 11022302463 10 16 Thus it appears that the first zero of f in the interval 0 1 has value x 0 2277581316 when rounded to ten decimal places The second zero in the interval 0 1 is approximately x 0 5 Newtons method nb 1 2 Cos 3p 2 4 3 To approximate the final zero of f in 0 1 we make an initial guess using the graph of f created earlier as a reference and apply Newton s method to obtain the successive approximations Taking x0 0 75 we obtain successive estimates similar as before In fact this value is exactly 0 5 since In 12 xn 0 75 our initial guess Print x0 PaddedForm xn 12 12 f x0 NumberForm f xn 12 k 0 a counter While Abs f xn 10 10 xn newton xn k k 1 Print x k PaddedForm xn 12 12 f x k NumberForm f xn 12 x0 0 750000000000 f x0 0 103553390593 x1 0 773903396439 f x1 0 00826202284179 x2 0 772248446679 f x2 0 0000325802639608 x3 0 772241868497 f x3 5 23180165857 10 10 x4 0 772241868391 f x4 0 The short nested list version is given by So the final zero rounded to ten decimal places is x 0 7722418684 In the following example Newton s method is illustrated graphically Example 2 Estimate all roots of the third degree polynomial function p x x3 4 x 1 We begin by graphing the polynomial y p x in the plane In 18 p x x3 4 x 1 Plot p x x 3 3 PlotStyle Blue 10 5 Out 19 3 2 1 1 5 10 15 2 3 4 Newtons method nb Clearly p has exactly three real zeros Let s use Newton s method as before to estimate these roots Suppose we set x0 1 As in Example 1 we use a function newton to obtain succesive estimates In 20 In 21 newton x x p x p x xn 1 0 our initial guess Print x0 PaddedForm xn 12 12 p x0 NumberForm p xn 12 k 0 a counter While Abs p xn 10 10 xn newton xn k k 1 Print x k PaddedForm xn 12 12 p x k NumberForm p xn 12 x0 1 000000000000 p x0 4 x1 3 000000000000 p x1 16 x2 2 304347826090 p x2 4 01873921262 x3 1 967489476620 p x3 0 74622305627 x4 1 869470470670 p x4 0 0557675569007 x5 1 860870682710 p x5 0 000414141645534 x6 1 860805856780 p x6 2 34600978644 10 8 x7 1 860805853110 p x7 0 Although our starting value of x0 1 was between the largest two of the three roots Newton s method has converged to the smallest of the three roots Finally we graph the approximations and the tangent lines at each pair xn p xn for n 1 2 3 4 5 so that we may see how xn 1 is attained graphically from xn at each stage As we saw in the introduction the idea of the method is as follows one starts with an initial guess which is reasonably close to the true root then the function is approximated by its tangent line at that point which can be computed using the tools of calculus and one computes the …
View Full Document
Unlocking...