The following is a simple Fortran 90 program to do
Newton's iteration.
program simple_newton_method
implicit none
double precision x, y, tol
integer i
write(*,*) 'input initial guess:'
read(*,*) y
write(*,*) 'input tolerance:'
read(*,*) tol
i=0
do i = 1,20
x = y
y = x - f(x)/fp(x)
write(*,'(1x,a,1x,i3,2(1x,d24.16))') 'i, old x, new x:', i, x, y
if(abs(y-x) < tol) exit
end do
contains
function f(x) result(value)
double precision x, value
value = tan(x) - x
end function f
function fp(x) result(value)
double precision x, value
value = 1d0/cos(x)**2 -1d0
end function fp
end program simple_newton_method