Gauss Jordan Method – Roots of Linear System of Equations | FORTRAN 95

Fortran Programming - Bottom Science
PROGRAM gauss_jordan

IMPLICIT NONE
REAL::A(20,20),t,v(20)
INTEGER::i,j,n,k

PRINT *, "============================================" 
PRINT *, "Find roots of linear system of equations using Gauss Jordan Method - [BY - www.BottomScience.com]" 
PRINT *, "============================================"

PRINT *,'GAUSS JORDAN'
PRINT *,'NO. OF ROWS'
READ(*,*)n

PRINT *,'ENTER ELEMENTS'

READ(*,*)((A(i,j),j=1,n+1),i=1,n)

PRINT *,'YOUR MATRIX - '

DO i=1,n
  write(*,*)(A(i,j),j=1,n+1)
END DO

DO j=1,n !J->ROWS
  DO i=1,n !I-> COLUMNS
    IF(i .ne. j) THEN
        t=A(i,j)/A(j,j)
        DO k=1,n+1
          A(i,k)=A(i,k)-(A(j,k)*t)
        END DO
    END IF
   END DO
END DO

PRINT *,'DIAGONAL MATRIX - '

DO i=1,n
  write(*,*)(A(i,j),j=1,n+1)
END DO

PRINT *,'SOLUTIONS '

DO i=1,n
  v(i)=A(i,n+1)/A(i,i)
  write(*,*)v(i)
END DO

END PROGRAM

Leave a Reply

Your email address will not be published.