next up previous
Next: Quadratic convergence Up: Newton's method Previous: Newton's method

newton.f

c      PROGRAM TO FIND A ROOT OF  f(x) = 0  USING VANILLA NEWTON's METHOD
         program newt
       implicit none
       real xold,tol
       real xnew
       real ff,ffprime,fold,fpold
       integer iter,itstart,itend

c      THE INITIAL GUESS FOR THE ROOT IS xold
c      FIND ROOT TO WITHIN A TOLERANCE  tol
c      THE FUNCTIONS f(x),f'(x) ARE DEFINED IN A SUBROUTINES GIVING ff,ffprime

c      DO A MAXIMUM OF itend ITERATIONS
       itstart=1
       itend=50

c      ENTER INITIAL GUESS, called xold, and TOL 

c      IF |ff(xold)| < tol  THEN xold IS A GOOD APPROXIMATION OF THE ROOT

C      MAIN ITERATION LOOP
       do iter=itstart,itend

c        DEFINE f(xold) and f'(xold)

c        AVOID DIVIDING BY 0

c        GET THE NEW ITERATE xnew BY THE NEWTON FORMULA

c        CHECK IF ff(xnew) IS A ROOT

c        PUT xold INTO xnew

       enddo


999    stop
       end

c****6****************************************************************72
       real function ff(x)
c      THIS FUNCTION SUBROUTINE COMPUTES THE VALUE OF f AT A POINT x

c      DEFINE ff

       return
       end

c****6****************************************************************72
       real function ffprime(x)
c      THIS FUNCTION SUBROUTINE COMPUTES THE VALUE OF f' AT A POINT x

c      DEFINE ffprime

       return
       end



Bruce Pitman
Wed Oct 11 12:23:54 EDT 1995