(*  Illustration of the Newton's method for solving nonlinear equations  *)

(*  First solve the equation f(x)=0 for f(x)=x^2-5 in order to find sqrt(5)  *)

(*  Define the function and find its derivative  *)

f[x_]=x^2-5

D[f[x],x]

(*  Define the initial guess and compute the initial value of the error  *)

x1 = 2

e1 = Abs[x1-Sqrt[5]];

N[e1,100]

(*  Start iterating; at each step compute the (absolute) error as the absolute value of the difference between the current and the true value and print 100 digits of the error  *)

x2 = x1 - (x1^2-5)/(2*x1)

e2 = Abs[x2-Sqrt[5]];

N[e2,100]

x3 = x2 - (x2^2-5)/(2*x2)

e3 = Abs[x3-Sqrt[5]];

N[e3,100]

x4 = x3 - (x3^2-5)/(2*x3)

e4 = Abs[x4-Sqrt[5]];

N[e4,100]

x5 = x4 - (x4^2-5)/(2*x4)

e5 = Abs[x5-Sqrt[5]];

N[e5,100]

x6 = x5 - (x5^2-5)/(2*x5)

e6 = Abs[x6-Sqrt[5]];

N[e6,100]

x7 = x6 - (x6^2-5)/(2*x6)

e7 = Abs[x7-Sqrt[5]];

N[e7,100]

(*  Here is the same procedure (using 10000 digits of the numbers in each computation) with overloading the value of x by the current value and printing the error at each step  *)

f[x_] := x^2-5;
x=N[2,10000];  
For[i=1, i≤12, i++, 
{x=x-f[x]/f'[x], 
error = Abs[x- Sqrt[5]], 
Print[i,"   ",1.0*error]
}
]