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

Fortran Programming - Bottom Science
PROGRAM gauss_eli
IMPLICIT NONE

REAL::A(20,20),k1,k2,v(20),c
INTEGER::i,j,n,k

PRINT *, "============================================" 
PRINT *, "Program to find roots of linear system of equations using Gauss elimination method - [BY - www.BottomScience.com]" 
PRINT *, "============================================"

PRINT *,'GAUSS ELIMINATION - WITHOUT PIVOTING'
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 k=1,n-1
  k1=A(k,k)
    DO i=k+1,n
        k2=A(i,k)/k1
        DO j=k,n+1
          A(i,j)=A(i,j)-(k2*A(k,j))
        END DO
    END DO
END DO

PRINT *,'UPPER TRIANGULAR MATRIX - '
DO i=1,n
  write(*,*)(A(i,j),j=1,n+1)
END DO

!LAST ELEMENT
v(n)=A(n,n+1)/A(n,n)

!REST OF THE ELEMENTS

DO i=n-1,1,-1
c=0.
  DO j=i+1,n
    c=c+A(i,j)*v(j)!DETECTING LAST VALUE
  END DO

v(i)=(A(i,n+1)-c)/a(i,i)
END DO

PRINT *,'SOLUTIONS ARE - '
DO i=1,n
  write(*,*)v(i)
END DO

END PROGRAM

Leave a Reply

Your email address will not be published.