Function Repository Resource:

NewtonMethodPlot

Source Notebook

Plot the function together with a graphical display of the Newton iterations approximating its root

Contributed by: Dennis M Schneider

ResourceFunction["NewtonMethodPlot"][f,{x,xmin,xmax},pt]

returns a plot of f from x=xmin to x=xmax, together with illustrations representing the iterations of Newton’s root-finding method, starting at x=pt.

Details and Options

Starting with an initial guess x0 for the zero of the function, the next approximation x1 is the horizontal intercept of the tangent line at x0. The process is repeated until a sufficiently accurate value is obtained.
The following options are accepted:
"DrawGraph"Truewhether to include the graph
"Iterations"5the number of iterations to perform
"LineStyle"Thickgraphics directive to specify the style for the line
"PointStyle"PointSize[0.016]graphics directive to specify the style for the point
"PrintDisplay"Truewhether to include the table of iteration values
WorkingPrecisionMachinePrecisiondetermines the number of digits used in internal calculations

Examples

Basic Examples (4) 

Illustrate Newton’s method on a simple function:

In[1]:=
ResourceFunction["NewtonMethodPlot"][x^3 - 2 + 3 x, {x, -3, 5}, 4]
Out[1]=

Increase the number of iterations:

In[2]:=
ResourceFunction["NewtonMethodPlot"][x^3 - 2 + 3 x, {x, -3, 5}, 4, "Iterations" -> 10]
Out[2]=

Newton’s method can cycle:

In[3]:=
ResourceFunction[
 "NewtonMethodPlot"][-x^3 + 2 x^2 + 5 x + 6, {x, -2, 2}, 1, PlotRange -> All]
Out[3]=

Newton’s method may "converge" to a cycle:

In[4]:=
ResourceFunction["NewtonMethodPlot"][-x^3 + 2 x - 2, {x, -2, 2}, .1, "Iterations" -> 15, PlotRange -> All]
Out[4]=

Possible Issues (2) 

Use Surd when necessary:

In[5]:=
ResourceFunction["NewtonMethodPlot"][x^(1/3) + 1, {x, -2, 0}, -3/2]
In[6]:=
ResourceFunction["NewtonMethodPlot"][Surd[x, 3] + 1, {x, -2, 0}, -3/2]
Out[6]=

Three examples that show that Newton’s method may converge to an unexpected root when it begins or lands near a zero of the derivative:

In[7]:=
ResourceFunction["NewtonMethodPlot"][Sin[x^2], {x, 0, 3}, 1.28, "Iterations" -> 10]
Out[7]=
In[8]:=
ResourceFunction["NewtonMethodPlot"][Sin[x^2], {x, 0, 3}, 1.29, "Iterations" -> 10]
Out[8]=
In[9]:=
ResourceFunction["NewtonMethodPlot"][Sin[x^2], {x, 0, 3}, 1.3, "Iterations" -> 10]
Out[9]=

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 20 August 2019

Related Resources

License Information