dgefa.f 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. *DECK DGEFA
  2. SUBROUTINE DGEFA (A, LDA, N, IPVT, INFO)
  3. C***BEGIN PROLOGUE DGEFA
  4. C***PURPOSE Factor a matrix using Gaussian elimination.
  5. C***LIBRARY SLATEC (LINPACK)
  6. C***CATEGORY D2A1
  7. C***TYPE DOUBLE PRECISION (SGEFA-S, DGEFA-D, CGEFA-C)
  8. C***KEYWORDS GENERAL MATRIX, LINEAR ALGEBRA, LINPACK,
  9. C MATRIX FACTORIZATION
  10. C***AUTHOR Moler, C. B., (U. of New Mexico)
  11. C***DESCRIPTION
  12. C
  13. C DGEFA factors a double precision matrix by Gaussian elimination.
  14. C
  15. C DGEFA is usually called by DGECO, but it can be called
  16. C directly with a saving in time if RCOND is not needed.
  17. C (Time for DGECO) = (1 + 9/N)*(Time for DGEFA) .
  18. C
  19. C On Entry
  20. C
  21. C A DOUBLE PRECISION(LDA, N)
  22. C the matrix to be factored.
  23. C
  24. C LDA INTEGER
  25. C the leading dimension of the array A .
  26. C
  27. C N INTEGER
  28. C the order of the matrix A .
  29. C
  30. C On Return
  31. C
  32. C A an upper triangular matrix and the multipliers
  33. C which were used to obtain it.
  34. C The factorization can be written A = L*U where
  35. C L is a product of permutation and unit lower
  36. C triangular matrices and U is upper triangular.
  37. C
  38. C IPVT INTEGER(N)
  39. C an integer vector of pivot indices.
  40. C
  41. C INFO INTEGER
  42. C = 0 normal value.
  43. C = K if U(K,K) .EQ. 0.0 . This is not an error
  44. C condition for this subroutine, but it does
  45. C indicate that DGESL or DGEDI will divide by zero
  46. C if called. Use RCOND in DGECO for a reliable
  47. C indication of singularity.
  48. C
  49. C***REFERENCES J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
  50. C Stewart, LINPACK Users' Guide, SIAM, 1979.
  51. C***ROUTINES CALLED DAXPY, DSCAL, IDAMAX
  52. C***REVISION HISTORY (YYMMDD)
  53. C 780814 DATE WRITTEN
  54. C 890831 Modified array declarations. (WRB)
  55. C 890831 REVISION DATE from Version 3.2
  56. C 891214 Prologue converted to Version 4.0 format. (BAB)
  57. C 900326 Removed duplicate information from DESCRIPTION section.
  58. C (WRB)
  59. C 920501 Reformatted the REFERENCES section. (WRB)
  60. C***END PROLOGUE DGEFA
  61. INTEGER LDA,N,IPVT(*),INFO
  62. DOUBLE PRECISION A(LDA,*)
  63. C
  64. DOUBLE PRECISION T
  65. INTEGER IDAMAX,J,K,KP1,L,NM1
  66. C
  67. C GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
  68. C
  69. C***FIRST EXECUTABLE STATEMENT DGEFA
  70. INFO = 0
  71. NM1 = N - 1
  72. IF (NM1 .LT. 1) GO TO 70
  73. DO 60 K = 1, NM1
  74. KP1 = K + 1
  75. C
  76. C FIND L = PIVOT INDEX
  77. C
  78. L = IDAMAX(N-K+1,A(K,K),1) + K - 1
  79. IPVT(K) = L
  80. C
  81. C ZERO PIVOT IMPLIES THIS COLUMN ALREADY TRIANGULARIZED
  82. C
  83. IF (A(L,K) .EQ. 0.0D0) GO TO 40
  84. C
  85. C INTERCHANGE IF NECESSARY
  86. C
  87. IF (L .EQ. K) GO TO 10
  88. T = A(L,K)
  89. A(L,K) = A(K,K)
  90. A(K,K) = T
  91. 10 CONTINUE
  92. C
  93. C COMPUTE MULTIPLIERS
  94. C
  95. T = -1.0D0/A(K,K)
  96. CALL DSCAL(N-K,T,A(K+1,K),1)
  97. C
  98. C ROW ELIMINATION WITH COLUMN INDEXING
  99. C
  100. DO 30 J = KP1, N
  101. T = A(L,J)
  102. IF (L .EQ. K) GO TO 20
  103. A(L,J) = A(K,J)
  104. A(K,J) = T
  105. 20 CONTINUE
  106. CALL DAXPY(N-K,T,A(K+1,K),1,A(K+1,J),1)
  107. 30 CONTINUE
  108. GO TO 50
  109. 40 CONTINUE
  110. INFO = K
  111. 50 CONTINUE
  112. 60 CONTINUE
  113. 70 CONTINUE
  114. IPVT(N) = N
  115. IF (A(N,N) .EQ. 0.0D0) INFO = N
  116. RETURN
  117. END