(* :Author: Christopher Moretti *) (* :Summary: NewtonsMethod[expr,{x,seed},n] applies Newton'sMethod to finding a root of expr(x)=0 with an initial value of seed and n iteration.NewtonsMethod[expr,{x,seed},n,Digits->k] will use k decimal places of accuracy in the intial calculation." *) (* :History: Version 1.0 by Christopher Moretti, 1998 *) Clear[NewtonsMethod] Options[NewtonsMethod]={Digits->10}; NewtonsMethod[f_,{x_,s_},n_,opts___]:= Block[ {k,seed,d}, d=({Digits}/.{opts}/.Options[NewtonsMethod])[[1]]; seed=N[s,d]; Print[ N[{seed,f/.x->seed},d]]; Do[ seed=N[seed-(( f/.x->seed)/(D[f,x]/.x->seed)),d]; Print[N[{seed,f/.x->seed},d]];,{k,1,n}]; Return[seed]; ]; NewtonsMethod::usage= "NewtonsMethod[expr,{x,seed},n] applies Newton'sMethod to finding a root of expr(x)=0 with an initial value of seed and n iteration.NewtonsMethod[expr,{x,seed},n,Digits->k] will use k decimal places of accuracy in the intial calculation." (* Example: NewtonsMethod[Sin[x],{x,3},10,Digits->30] *)