Learning Newton's Method

f1[x_]:= x^2 -2              (* drop down menu function definitions *)

f21[x_]:= Cos[x]

f3[x_]:=x^3 -7

f5[x_]:=x^3 -3x^2 + x -1

newton[f_,x0_,a_,b_,n_]:=Module[{list=NestList[#-((f[#])/(f'[#])) &,x0,n]},Column[{TraditionalForm@Text@Style[Row[{HoldForm[(Subscript[{(Subscript[x, k])}, k=0]^n)]," = ", list}],14],Plot[f[x],{x,a,b},PlotRange-> All,AxesLabel-> {Style[x,16],Style[y,16]},PlotStyle-> Thickness[.006],Epilog->{{Red,Thickness[.002],Arrowheads[.03],Arrow[Most[Flatten[Map[{{#,0},{#,f[#]}} &,list],1]]]},{PointSize[0.015],Point[{x0,0}]}},ImageSize->{600,325}]},Center]]

Manipulate[newton[d,N[x0],0,2π,n],
{{d,f21,"function"},{f1-> TraditionalForm[x^2 -2], f21-> TraditionalForm[Cos[x]],f3-> TraditionalForm[x^3 -7],f5-> TraditionalForm[x^3 -3x^2 + x -1]},ControlType-> PopupMenu},
{{n,1,"n"},{0,1,2,3,4,5,6},ControlType->SetterBar},
{{x0,.6,Subscript["x","0"]},0.01,6.11,Appearance->"Labeled" },SaveDefinitions->True]

CAPTION

This Demonstration illustrates geometrically Newton's method for approximating roots. The available functions illustrate places where Newton's method yields interesting behavior.

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Learning Newton's Method" from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/LearningNewtonsMethod/

Contributed by: Angela Sharp, Chad Pierson, and Joshua Fritz

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »