Newton’s methodIntroductionIn this laboratory we will become familiar with Newton's method for attaining successive approximations to the zero of a func-tion. Newton’s method is also known as the Newton-Raphson method. The While and For loop statements for the repeti-tive execution of code, as well as the Print command, will be used. Successive approximations will also be illustratedgraphically.Newton's method is a technique for approximating the zeros of a function. It is based on the observation that, in most cases, if wemake 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 atx0, 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)stapproximation is given by:xn+1= xn-f xnf'xn.ExamplesExample 1 is based on prior Math 149 Maple laboratories. Example 2 was created in Mathematica for Math 151.ü Example 1Find all numbers x in the interval 0, 1 for which cos3 p x22= x.To determine the number of solutions to this problem, we plot a graph of the functionsFx =cos3 p x22 and Gx = x for 0 < x < 1. Then the solutions to this problem are all the values of x at which Fx = Gx . In[1]:=funcFx_ : Cos3 Pi x 2 ^2funcGx_ : xIt is also evident that the solutions to our problem are the zeros of the function f x = Gx - Fx.We plot a graph of the functions f , F, and G to illustrate our remark.In[3]:=fx_ : funcGx funcFxPlotfuncFx, funcGx,fx, x, 0, 1, PlotStyle Red, Blue, GreenOut[4]=0.2 0.4 0.6 0.8 1.0-1.0-0.50.51.0We 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 iterationmentioned in the Introduction.In[5]:=newtonx_ : x fxf'xIf we iterate with this function, then the iteration does not remember all intermediate values xn, but instead constantly overwritesthe 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 toseparate 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 Ø xThe following code iterates Newton's method until we have found an x for which f x is less than 10-10 in absolute value (seethe 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", PaddedFormxn, 12, 12,", fx0", NumberFormfxn,12;k 0; a counter WhileAbsfxn 10^10,xn newtonxn;k k 1;Print"x"k,"", PaddedFormxn, 12, 12,", f", "x"k,"", NumberFormfxn,12;x0 0.250000000000, fx00.103553390593x1 0.226096603561, fx10.00826202284178x2 0.227751553321, fx20.0000325802639608x3 0.227758131503, fx35.23180249123 1010x4 0.227758131609, fx41.11022302463 1016Thus, 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. 2 Newtons method.nbIn fact, this value is exactly 0.5, since 12= Cos3 p42.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 applyNewton's method to obtain the successive approximations. Taking x0= 0.75 we obtain successive estimates similar as before.In[12]:=xn 0.75; our initial guess Print"x0", PaddedFormxn, 12, 12,", fx0", NumberFormfxn,12;k 0; a counter WhileAbsfxn 10^10,xn newtonxn;k k 1;Print"x"k,"", PaddedFormxn, 12, 12,", f", "x"k,"", NumberFormfxn,12;x0 0.750000000000, fx00.103553390593x1 0.773903396439, fx10.00826202284179x2 0.772248446679, fx20.0000325802639608x3 0.772241868497, fx35.23180165857 1010x4 0.772241868391, fx40.The short nested list version is given bySo the final zero rounded to ten decimal places is x = 0.7722418684.In the following example Newton's method is illustrated graphically.ü Example 2Estimate all roots of the third degree polynomial function px = x3- 4 x - 1. We begin by graphing the polynomial y = px in the plane.In[18]:=px_ : x3 4 x 1Plotpx, x, 3, 3, PlotStyle BlueOut[19]=-3 -2 -1 1 2 3-15-10-5510Newtons method.nb 3Clearly, 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]:=newtonx_ : x pxp'xIn[21]:=xn 1.0; our initial guess Print"x0", PaddedFormxn, 12, 12,", px0", NumberFormpxn,12;k 0; a counter WhileAbspxn 10^10,xn newtonxn;k k 1;Print"x"k,"", PaddedFormxn, 12, 12,", p", "x"k,"", NumberFormpxn,12;x0 1.000000000000, px04.x13.000000000000, px116.x22.304347826090, px24.01873921262x31.967489476620, px30.74622305627x41.869470470670, px40.0557675569007x51.860870682710, px50.000414141645534x61.860805856780, px62.34600978644 108x71.860805853110, px70.Although our starting value of x0= 1 was between the largest two of the three roots, Newton’s method has converged to
View Full Document