Newton's Method

Author

Eric W. Weisstein
March 6, 2006

This notebook downloaded from http://mathworld.wolfram.com/notebooks/NumericalMath/NewtonsMethod.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/NewtonsMethod.html.

©2006 Wolfram Research, Inc. except for portions noted otherwise

Code

NewtonsMethodList[f_,{x_,x0_},n_]:=NestList[#-((Function[x,f][#])/(Derivative[1][Function[x,f]][#]))&,x0,n]

Examples

Plot[Tan[x]-x,{x,0,5},PlotStyle->Red]

FindRoot[Tan[x]==x,{x,2}]

NewtonsMethodList[Tan[x]-x,{x,4.5},10]

Examples

NewtonIteration[f_,z_] := z - (f - 1)/Derivative[1][Function[z,f]][z];

(z^2)-(2^z)

FullSimplify[NewtonIteration[z^2-2^z,z]]

newt=Compile[{{z, _Complex}}, 
      Length[FixedPointList[#+((1+(2^(#))-((#)^2))/(2 #-(2^(#)) Log[2]))&,z,100]]];

Compiling doesn't help because this iteration is unstable at machine precision

ListDensityPlot[Table[newt[x+I y],{x,-10,10,1/10},{y,-8,8,1/10}],
Mesh->False,
ColorFunction->(Hue[2#]&),
Frame->False]//Timing

So, assume convergence once iterations get within (10^(-6))(or so)

g1=DensityPlot[Length[FixedPointList[#+((1+(2^(#))-((#)^2))/(2 #-(2^(#)) Log[2.]))&,x+I y,20,SameTest->(Abs[#1-#2]<10^-6&)]],{y,-12,12},{x,-12,12},
Mesh->False,
PlotPoints->750,
FrameLabel->TraditionalForm/@{x,y},
ColorFunction->(Hue[2#]&),
ImageSize->400];//Timing

(z^3)-(3^z)

FullSimplify[NewtonIteration[z^3-3^z,z]]

g2=DensityPlot[Length[FixedPointList[#+((1+(3^(#))-((#)^3))/(3 ((#)^2)-(3^(#)) Log[3.]))&,x+I y,20,SameTest->(Abs[#1-#2]<10^-6&)]],{y,-12,12},{x,-12,12},
Mesh->False,
PlotPoints->750,
FrameLabel->TraditionalForm/@{x,y},
ColorFunction->(Hue[2#]&),
ImageSize->400];//Timing

Show[GraphicsArray[{g1,g2}],ImageSize->500]

(x^3)+1

Simplify[NewtonIteration[z^3-1,z]]

newt = Compile[{{z, _Complex}}, 
      Length[FixedPointList[2(1+#^3)/3/#^2 &, z, 35]]];

DensityPlot[newt[b+a I],{a,-.2,.2},{b,.2,-.2},
Mesh->False,PlotRange->All,PlotPoints->500,ColorFunction->Hue]//Timing

DensityPlot[newt[b+a I],{a,-1.1,1.1},{b,1.1,-1.1},
Mesh->False,PlotRange->All,PlotPoints->500,ColorFunction->Hue]//Timing

ListDensityPlot[Table[newt[b+a I],{a,-1.1,1.1,0.005},{b,1.1,-1.1,-0.005}],
Mesh->False,PlotRange->All,ColorFunction->Hue]//Timing

DensityPlot[newt[b+a I],{a,-5,5},{b,5,-5},
Mesh->False,PlotRange->All,PlotPoints->500,ColorFunction->Hue]//Timing

Powers

Simplify[NewtonIteration[z^n,z]]

FixedPointList[# (n-1+#^(-n))/n &/. n->3, .5-.5I,10]

newt = Compile[{{n, _Integer}, {z, _Complex}}, 
      Arg[FixedPoint[# (n-1+#^(-n))/n &, z, 35]]];

Show[GraphicsArray[Partition[Table[ListDensityPlot[Table[newt[n,b+a I],{a,-1.1,1.1,0.005},{b,1.1,-1.1,-0.005}],
Mesh->False,
DisplayFunction->Identity,
PlotRange->All,
ColorFunction->Hue,
Frame->False],{n,3,11}],3],GraphicsSpacing->0.05]]//Timing