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

f[x_]:=x^3+1

?Nest

Nest[g,x0,3]

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

newt[g,x0,1]

newt[f,x0,1]

Table[newt[f,0.2,k],{k,1,10}]

TableForm[Table[N[newt[f,1/5,k],50],{k,1,12}]]

?Show

?Plot

?Graphics

?Line

graficonewt[f_,x0_,nit_]:=Show[{
Plot[f[x],{x,-4,4},PlotStyle->{Thick,Blue},ImageSize->400,AspectRatio->Automatic,PlotRange->{-4,4}],
Graphics[{PointSize[0.02],Point[{{x0,0},{x0,f[x0]}}]}],
Graphics[{Thick,Line[{{N[newt[f,x0,1],50],0},{x0,f[x0]}}]}]
}
]

graficonewt[f,-.4,1]

TableForm[Table[N[newt[f,1/5,k],50],{k,1,12}]]

graficonewt[f_,x0_,nit_]:=Show[{
Plot[f[x],{x,-6,6},PlotStyle->{Thick,Blue},ImageSize->400,AspectRatio->Automatic,PlotRange->{{1,5},{-2,2}}],
Graphics[{PointSize[0.02],Point[Table[{N[newt[f,x0,k]],0},{k,0,nit}]]}],
Graphics[Table[{Thick,Line[{{N[newt[f,x0,h+1]],0},{N[newt[f,x0,h]],f[N[newt[f,x0,h]]]}}]},{h,0,4}]]
}
]

Manipulate[graficonewt[f,x0,3],{x0,0.01,4}]

f2[x_]:=0.1x^2-1

graficonewt[f2,2,3]

grafico[f_,x0_,npas_]:=
Plot[f[x],{x,-2,2},PlotStyle->{Thick,Blue},ImageSize->400,
Epilog->{{PointSize[0.02],Point[Table[{newt[f,x0,k],f[newt[f,x0,k]]},{k,0,npas-1}]]},
{PointSize[0.02],Red,Point[Table[{newt[f,x0,k],0},{k,0,npas}]]},
Table[Line[Table[{h,f[newt[f,x0,k]]+f'[newt[f,x0,k]](h-newt[f,x0,k])},{h,-2,2,4}]],{k,0,npas-1}]
}
]

grafico[f,1.8,1]

grafico[f,1.8,2]

Manipulate[grafico[f,1.8,j],{j,0,10,1}]

Table[newt[f,1.8,k],{k,0,10}]

Table[N[newt[f,1.8,k],50],{k,0,10}]

Table[N[newt[f,18/10,k],50],{k,0,10}]

f1[x_]:=1+x^3/(x^2-1)

grafico[f1,-0.8,0]

Manipulate[grafico[f1,-0.8,j],{j,0,10,1}]

Manipulate[grafico[f1,0.6,j],{j,0,10,1}]

Table[N[newt[f,6/10,k],50],{k,0,6}]

Manipulate[Table[N[newt[f,6/10,k],50],{k,0,j}],{j,0,10,1}]

f2[x_]:=x^2-2

newt[f2,x0,1]

Expand[%]

Manipulate[grafico[f2,1,j],{j,0,10,1}]

Table[newt[f2,14/10,k],{k,0,5}]

Table[N[newt[f2,14/10,k],50],{k,0,6}]