Subrotina para inverter matrix em Fortran

      SUBROUTINE SYMIN (A,N)
C
C      THIS SUBROUTINE INVERTS A SYMMETRIC MATRIX.
C      ***** INPUT DATA *****
C      A  =  A SYMMETRIC MATRIX
C      N  =  THE RANK OF THE MATRIX. N MUST BE LESS THAN 20.
C      ***** OUTPUT DATA *****
C      A  =  THE INVERSE OF THE INPUT MATRIX
C
        implicit integer*2 (i-n)
        implicit double precision(a-h,o-z)
      DIMENSION A(N,N)
      DIMENSION P(20),Q(20),R(20)
13      FORMAT(13H0SYMIN FAILED)
        write(*,599)
599     format(' entering symin')
      ZERO = 0.0
      ONE = 1.0
      DO 1 M=1,N
1      R(M) = ONE
      DO 2 M=1,N
      BIG = ZERO
      DO 3 L=1,N
      AB = ABS(A(L,L))
      IF(AB-BIG)3,3,4
4      IF(R(L))14,3,14
14      BIG = AB
      K = L
3      CONTINUE
      IF(BIG)6,5,6
5      WRITE (*,13)
      RETURN
6      R(K) = ZERO
      Q(K) = ONE/A(K,K)
      P(K) = ONE
      A(K,K) = ZERO
      KM1 = K-1
      IF(KM1.EQ.0) GO TO 16
      DO 7 L=1,KM1
      P(L) = A(L,K)
      IF(R(L))9,8,9
8      Q(L) = A(L,K)*Q(K)
      GO TO 7
9      Q(L) = -A(L,K)*Q(K)
7      A(L,K) = ZERO
16      CONTINUE
      KP1 = K+1
      IF(KP1.GT.N) GO TO 17
      DO 15 L=KP1,N
      IF(R(L))12,11,12
12      P(L) = A(K,L)
      GO TO 10
11      P(L) = -A(K,L)
10      Q(L) = (-A(K,L))*Q(K)
15      A(K,L) = ZERO
17      CONTINUE
      DO 2 L=1,N
      DO 2 K=L,N
2      A(L,K) = A(L,K) + P(L)*Q(K)
      M = N+1
      L = N
      DO 27 K=2,N
      M = M-1
      L = L-1
      DO 27 J=1,L
27      A(M,J) = A(J,M)
      RETURN
      END