Newton' s Method, only to look for the best parameter, rather than x.

Andy Long
Spring, 2018

I borrowed the strategy of

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

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

So what if we rethink Newton’s method, and pretend that we have a point, (xx,yy), and we’re trying to fit a (one parameter) model M(x;β) to this point? That is, we’re trying to find the value of β such that yy=M(xx;β). 

So we’ll start with a good estimate for the parameter, call it (Subscript[β, 0]), and try to find a better one. To find a better one, we’ll try to make f(β)=yy-M(xx;β)=0. Since we’re looking for zeros of this function (f(β)), we know what to use --Newton’s method!

 (Subscript[β, 1])=(Subscript[β, 0])-((f((Subscript[β, 0])))/(f'((Subscript[β, 0]))))

Clear everything possibly in our way:

Clear["Global`*"]

Here’s our point:

xx=1.0;
yy=Exp[-0.2 xx]; 
(* 
so for the model f3 below, β=-0.2 
*)

Here are some models that we can try. One of them will turn out to be a surprise!:)

f1[β_]:= yy-(β xx^2 -3 )            (* drop down menu function definitions *)
f2[β_]:= yy-Cos[β xx]
f3[β_]:=yy-Exp[β xx]

xx
yy
f1[3.8187307530779817`]
f2[0.6115993522446163`]
f3[-.2]

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

Manipulate[newton[d,N[a],-2,2,n],
{{d,f2,"function"},{f1-> TraditionalForm[y-(β x^2 -3)], f2-> TraditionalForm[y-Cos[β x]],f3-> TraditionalForm[y-Exp[β x]]},ControlType-> PopupMenu},
{{n,1,"n"},{0,1,2,3,4,5,6},ControlType->SetterBar},
{{a,.6,Subscript["β","0"]},-2,2,Appearance->"Labeled" },SaveDefinitions->True]