(*           Metodo di Newton per il calcolo degli zeri di f(x)      -2-             *)

?Nest

Nest[g,x0,3]

newt[f_,x0_,k_]:=Nest[#-f[#]/f'[#]&,x0,k]

f[x_]:=x^2-2

Expand[Together[newt[f,x0,1]]]

Table[newt[f,1,k],{k,1,7}]

TableForm[Table[{k,N[newt[f,1,k],50]},{k,1,7}]]

newt[f_,x0_,k_]:=Nest[#-f[#]/f'[#]&,x0,k]

zero[f_,x0_,k_]:=Block[{n=1,xn=0},While[Abs[Sqrt[2]-xn]>10^(-k),xn=N[newt[f,x0,n],2k];n=n+1];
Return[{n-1,N[xn,k+1]}];
];

zero[f,1,10]

zero[f,1,20]

zero[f,1,40]

zero[f,1,55]

N[Sqrt[2],58]

zero[f,1,500]

N[Sqrt[2],500]

zero[f,1.,40]

zerof[f_,x0_,k_]:=Block[{n=1,xn=0,xnm1=1},While[Abs[xnm1-xn]>10^(-k),
xnm1=xn;
xn=N[newt[f,x0,n],2k];n=n+1];
Return[{n-1,N[xn,k+1]}];
];

N[Pi,500]

zerof[Sin,2,500][[2]]

zerof[Sin,2,500]

zerof[Sin,2,500][[2]]-zerof[Sin,2,500][[2]]

zerof[Sin,2,50]

zerof[Sin,1,10]

zerof[Sin,2,10]

TableForm[Table[{k,N[newt[f,3,k],20]},{k,1,7}]]

TableForm[Table[{k,N[newt[f,1,k],55]},{k,1,8}]]

a=N[newt[f,1,4],55]

FullForm[a]

FullForm[ToString[a]]

Characters[ToString[a]]

Take[Characters[ToString[a]],10]

Style[Take[Characters[ToString[a]],10],FontColor->Red]

Map[Style[#,FontColor->Red]&,Take[Characters[ToString[a]],10]]

a

Print[Style[N[a,10],FontColor->Red],StringDrop[ToString[a],11]]

(* " :> "  si digita con  " :> "    *)

StringReplace[ToString[a],x:(_):>"\!\(\*StyleBox[\""<>x<>"\",FontColor->RGBColor[1,0,0],FontSize->18,FontWeight->\"Bold\"]\)"]

Manipulate[StringJoin[StringReplace[StringTake[ToString[a],k],x:(_):>"\!\(\*StyleBox[\""<>x<>"\",FontColor->RGBColor[1,0,0],FontSize->18,FontWeight->\"Bold\"]\)"],StringDrop[ToString[a],k]],{k,1,Length[Characters[ToString[a]]],1}]