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

f[x_]:=x^3+1

?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]

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

zerof[Sin,2,50]

zerof[Sin,1,10]

zerof[Sin,2,10]

Plot[x^7-2x^6+3x^5-x^4+1,{x,-10,10}]

g[x_]:=x^7-2x^6+3x^5-x^4+1

zerof[g,-1,10]

-0.69187024893022299980886879227000315982`11.

SetPrecision[-0.69187024893,200]

zerof[g,SetPrecision[-0.69187024893,200],100]

Manipulate[Plot[x^7-2x^6+3x^5-x^4+1,{x,-k,k}],{{k,10},0.001,10}]

h[x_]:=x^7+2x^6-3x^5+x^4+4x^3-3x^2+x-1

Plot[h[x],{x,-3.5,1.8}]

zerof[h,-3,10]

zerof[h,-2,10]

zerof[h,1,10]

zerof[h,1,30]

Manipulate[Plot[h[x],{x,-k,k}],{{k,10},0.001,10}]