<

Question: Newton's method programming help

Hi can someone please help me . My program gives me the correct solution but it crashes afterwards. Can anyone tell me whats wrong with the program please.

 

restart:
f:=x->x^2-5:
v:=diff(f(x),x):
x:=1:

n:=0.0001:
err:=n+1:

     while err>n do
        a:=x-(f(x)/eval(v(x))):
          print(evalf(a)):
        x:=a:
        err:=abs(evalf(a)):
 
    end do:

                                     3.
                                 2.333333333
                                 2.238095238
                                 2.236068896
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
                                 2.236067977
Warning,  computation interrupted

 

Please Wait...