C     N EQUATIONS WITH M UNKNOWNS
      INTEGER PV,RANK
      DIMENSION A(10,20)
      DATA N,M/3,4/
      DATA (A(1,J), J=1,5)/1.,-2.,1.,1.,4./
      DATA (A(2,J), J=1,5)/2.,1.,-3.,-1.,6./
      DATA (A(3,J), J=1,5)/1.,-7.,-6.,2.,6./
      PRINT*
      PRINT*,'  N EQUATIONS WITH M UNKNOWNS'
      PRINT*
      EPS=1.0
      DO 10 L=1,100
         IF (EPS+1.LE.1) GOTO 15
         EPS=EPS/2
10    CONTINUE
15    EPS=EPS*2
      PRINT*,'MACHINE EPSILON=', EPS
      EPS2=EPS*2
      PRINT*,'N(NUMBER OF EQUATIONS)=',N
      PRINT*,'M(NUMBER OF UNKNOWNS) =',M
      PRINT*
      PRINT *,'AUGMENTED MATRIX (LAST COLUMN: INHOMOGENEOUS TERM)'
      CALL LIST(A,M,N)
50    CONTINUE
      PRINT*
      DET=1.0
      I=0
      DO 500 K=1,N
         PV=K
90       I=I+1
         IF(I.GT.M) GOTO 600
         DO 100 J=K+1,N
            IF (ABS(A(PV,I)).LT.ABS(A(J,I))) PV=J
100      CONTINUE
         IF (PV.EQ.K.AND. A(K,I).EQ.0) GOTO 90
         IF (PV.EQ.K) GOTO 340
300      DO 320 JC=I,M+1
               TM=A(K,JC)
               A(K,JC)=A(PV,JC)
               A(PV,JC)=TM
320      CONTINUE
      DET=-DET
340   Z=A(K,I)
      DET=DET*Z
      RANK=K
      DO 330 J=I,M+1
      A(K,J)=A(K,J)/Z
330   CONTINUE
         DO 400 JR=1,N
            IF (JR.EQ.K) GOTO 400
            IF (A(JR,I).EQ.0) GOTO 400
            R=A(JR,I)
            DO 390 KC=I,M+1
               A(JR,KC)=A(JR,KC)-R*A(K,KC)
               IF (ABS(A(JR,KC)/A(K,KC)).LT.EPS2) A(JR,KC)=0
390      CONTINUE
400     CONTINUE
500   CONTINUE
      DO 520 J=1,M
         IF (A(N,J).EQ.0) GOTO 520
         DO 510 JR=J,M+1
            A(N,JR)=A(N,JR)/A(N,J)
510      CONTINUE
        A(N,J)=1.0
        GOTO 600
520   CONTINUE
600   IF (RANK.EQ.K) GOTO 640
      KONSIS=0
      DO 620 J=RANK+1,N
         IF (A(J,M+1).NE.0) KONSIS=KONSIS+1
620   CONTINUE
640   PRINT*,'RANK OF THE MATRIX =', RANK
      PRINT*,'DETERMINANT        =', DET
      PRINT*
      PRINT*,'REDUCED MATRIX :'
      CALL LIST(A,M,N)
      PRINT*
      IF (KONSIS .NE.0) THEN
        PRINT*,' WARNING:THE MATRIX IS NOT CONSISTENT.'
        ENDIF
      END
C***************
      SUBROUTINE LIST(A,M,N)
      DIMENSION A(10,20)
      PRINT *
      DO  I=1,N
      PRINT 30, (A(I,J), J=1,M+1)
         END DO
      PRINT*
30    FORMAT(1X,1P6E12.4)
      RETURN
      END










