===================================================================================
Program to find solutions to equations of the form f(x)=0 using
Newton-Raphson Method
LANGUAGE :: FORTRAN 95
Compiler :: GNU Fortran
===================================================================================
PROGRAM newtonRaphson
INTEGER i,n
REAL x,x0,e
WRITE(*,*)'Enter the maximum number of iterations'
READ*,n
WRITE(*,*)'Enter the trial solution'
READ*,x0
WRITE(*,*)'Enter the tolerance'
READ*,e
WRITE(*,*)'Iterations:'
DO i=1,n
x=x0-f(x0)/df(x0)
WRITE(*,10)i,x,f(x)
IF (ABS(x-x0)<=e) EXIT
x0=x
END DO
10 FORMAT(/,1x,'Iteration',I2,':',4X,'x=',F12.9,4X,'f(x)=',F12.8)
PRINT*,'THE APPROXIMATE SOLUTION IS',x
STOP
END PROGRAM
REAL FUNCTION f(x)
REAL x
f=(x**3)-(2*x)-5
RETURN
END
REAL FUNCTION df(x)
REAL x
df=3*(x**2)-2
RETURN
END