Bisection Method | FORTRAN 95

Bisection Method | FORTRAN 95

PROGRAM bisection
  IMPLICIT NONE
  REAL::f,ea=6,es=0.01,p,q,m
  INTEGER::c=0
  PRINT *,  '============================================'
  PRINT *, 'PROGRAM TO FIND THE ROOTS OF AN EQUATION USING - BISECTION METHOD [ BY - WWW.BOTTOMSCIENCE.COM ]'
  PRINT *, '============================================'
  PRINT *,'INITIAL APPROXIMATION (a,b)?'
  READ(*,*)p,q
  
  DO WHILE(ea>es)
    c=c+1
    IF (c>40) EXIT
      IF((f(p)*f(q))<0) THEN
        m=(p+q)/2
        PRINT *,'CURRENT ITERATED VALUE',m
        IF((f(p)*f(m))<0) THEN
          q=m
          ea=abs(((q-p)/q)*100)
        ELSE IF((f(p)*f(m))>0) THEN
          p=m
          ea=abs(((p-q)/p)*100)
        ELSE
          PRINT *,'ROOT IS - ',m
        END IF
      ELSE
        PRINT *,'INITIAL APPROXIMATION - WRONG'
     END IF
  END DO

IF (m<1*10E+20) THEN
  PRINT *,'FINAL ROOT IS',m
ELSE
  PRINT *,'ROOT IS DIVERGING [TRY OTHER RANGE FOR (p,q)]'
END IF
END PROGRAM

!FUNCTION
!CHANGE THE VALUE OF F TO CHANGE THE FUNCTION

REAL function f(x1)
  REAL::x1
  f=-0.6*(x1**2)+(2.4*x1)+5.5
  RETURN
END FUNCTION

OUTPUT

OUTPUT - BISECTION METHOD
OUTPUT – BISECTION METHOD

Leave a Reply

Your email address will not be published.