program newraph ! Program to solve the real equation f(x)=0 for real roots using the ! Newton-Raphson iteration scheme x = x - f(x)/f'(x) ! This program requires as input an initial approximation to the ! root of the equation f(x)=0 , where f(x) and its derivative f'(x) ! are specified in the accompanying function subprograms. The output ! is the required root accurate to tolerance TOL, if convergence is ! attained ! Declare variables: implicit none integer :: i real :: x, x0, tol, f, fdash character(len=1) :: check problem_loop: do ! Data prompt: write(*,*) 'Enter initial approximation to root and tolerance : ' ! Input and echo data: read(*,*) x0, tol write(*,20) x0, tol 20 format(/2x,' x0 = ',f14.7,5x,' tol = ',e8.2/) ! Header: write(*,*) 'Iteration Approximation' NRiteration_loop: do i = 1,100 x = x0 - f(x0)/fdash(x0) ! Newton-Raphson method. write(*,30) i,x 30 format(1x,i4,13x,e14.7) if(abs(x-x0)