Regula Falsi (False Position) Method | FORTRAN 95

Regula Falsi (False Position) Method | FORTRAN 95

PROGRAM regula_falsi
  IMPLICIT NONE
  REAL::f,ea=6,es=1,p,q,m,old_m

  WRITE(*,*) '============================================'
  WRITE(*,*) 'PROGRAM TO FIND THE ROOTS OF AN EQUATION USING - REGULA FALSI METHOD (FALSE POSITION) [ BY - WWW.BOTTOMSCIENCE.COM ]'
  WRITE(*,*) '============================================'
  PRINT *,'INITIAL APPROXIMATION (p,q)?'
  READ(*,*)p,q

  DO WHILE(ea>es)
    IF((f(p)*f(q))<0) THEN
      m=p-(((q-p)*f(p))/(f(q)-f(p)))
      IF(old_m==m) EXIT 
        old_m=m
        PRINT *,'CURRENT CALCULATED ROOT',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'
  END IF
END PROGRAM

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

REAL function f(x1)
  REAL::x1
  f=(3*x1)+sin(x1)-exp(x1)
  RETURN
END FUNCTION

OUTPUT

2. OUTPUT - REGULA FALSI (FALSE POSITION)
OUTPUT – REGULA FALSI (FALSE POSITION)

Leave a Reply

Your email address will not be published.