corth.F 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. SUBROUTINE CORTH(NM,N,LOW,IGH,AR,AI,ORTR,ORTI)
  2. C
  3. INTEGER I,J,M,N,II,JJ,LA,MP,NM,IGH,KP1,LOW
  4. REAL AR(NM,N),AI(NM,N),ORTR(IGH),ORTI(IGH)
  5. REAL F,G,H,FI,FR,SCALE
  6. C REAL SQRT,CABS,ABS
  7. C COMPLEX CMPLX
  8. C-----------------------------------------------------------------------
  9. C
  10. C THIS SUBROUTINE IS A TRANSLATION OF A COMPLEX ANALOGUE OF
  11. C THE ALGOL PROCEDURE ORTHES, NUM. MATH. 12, 349-368(1968)
  12. C BY MARTIN AND WILKINSON.
  13. C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 339-358(1971).
  14. C
  15. C GIVEN A COMPLEX GENERAL MATRIX, THIS SUBROUTINE
  16. C REDUCES A SUBMATRIX SITUATED IN ROWS AND COLUMNS
  17. C LOW THROUGH IGH TO UPPER HESSENBERG FORM BY
  18. C UNITARY SIMILARITY TRANSFORMATIONS.
  19. C
  20. C ON INPUT-
  21. C
  22. C NM MUST BE SET TO THE ROW DIMENSION OF TWO-DIMENSIONAL
  23. C ARRAY PARAMETERS AS DECLARED IN THE CALLING PROGRAM
  24. C DIMENSION STATEMENT,
  25. C
  26. C N IS THE ORDER OF THE MATRIX,
  27. C
  28. C LOW AND IGH ARE INTEGERS DETERMINED BY THE BALANCING
  29. C SUBROUTINE CBAL. IF CBAL HAS NOT BEEN USED,
  30. C SET LOW=1, IGH=N,
  31. C
  32. C AR AND AI CONTAIN THE REAL AND IMAGINARY PARTS,
  33. C RESPECTIVELY, OF THE COMPLEX INPUT MATRIX.
  34. C
  35. C ON OUTPUT-
  36. C
  37. C AR AND AI CONTAIN THE REAL AND IMAGINARY PARTS,
  38. C RESPECTIVELY, OF THE HESSENBERG MATRIX. INFORMATION
  39. C ABOUT THE UNITARY TRANSFORMATIONS USED IN THE REDUCTION
  40. C IS STORED IN THE REMAINING TRIANGLES UNDER THE
  41. C HESSENBERG MATRIX,
  42. C
  43. C ORTR AND ORTI CONTAIN FURTHER INFORMATION ABOUT THE
  44. C TRANSFORMATIONS. ONLY ELEMENTS LOW THROUGH IGH ARE USED.
  45. C
  46. C-----------------------------------------------------------------------
  47. LA = IGH - 1
  48. KP1 = LOW + 1
  49. IF (LA .LT. KP1) GO TO 200
  50. C
  51. DO 180 M = KP1, LA
  52. H = 0.0
  53. ORTR(M) = 0.0
  54. ORTI(M) = 0.0
  55. SCALE = 0.0
  56. C ********** SCALE COLUMN (ALGOL TOL THEN NOT NEEDED) **********
  57. DO 90 I = M, IGH
  58. 90 SCALE = SCALE + ABS(AR(I,M-1)) + ABS(AI(I,M-1))
  59. C
  60. IF (SCALE .EQ. 0.0) GO TO 180
  61. MP = M + IGH
  62. C ********** FOR I=IGH STEP -1 UNTIL M DO -- **********
  63. DO 100 II = M, IGH
  64. I = MP - II
  65. ORTR(I) = AR(I,M-1) / SCALE
  66. ORTI(I) = AI(I,M-1) / SCALE
  67. H = H + ORTR(I) * ORTR(I) + ORTI(I) * ORTI(I)
  68. 100 CONTINUE
  69. C
  70. G = SQRT(H)
  71. F = CABS(CMPLX(ORTR(M),ORTI(M)))
  72. IF (F .EQ. 0.0) GO TO 103
  73. H = H + F * G
  74. G = G / F
  75. ORTR(M) = (1.0 + G) * ORTR(M)
  76. ORTI(M) = (1.0 + G) * ORTI(M)
  77. GO TO 105
  78. C
  79. 103 ORTR(M) = G
  80. AR(M,M-1) = SCALE
  81. C ********** FORM (I-(U*UT)/H) * A **********
  82. 105 DO 130 J = M, N
  83. FR = 0.0
  84. FI = 0.0
  85. C ********** FOR I=IGH STEP -1 UNTIL M DO -- **********
  86. DO 110 II = M, IGH
  87. I = MP - II
  88. FR = FR + ORTR(I) * AR(I,J) + ORTI(I) * AI(I,J)
  89. FI = FI + ORTR(I) * AI(I,J) - ORTI(I) * AR(I,J)
  90. 110 CONTINUE
  91. C
  92. FR = FR / H
  93. FI = FI / H
  94. C
  95. DO 120 I = M, IGH
  96. AR(I,J) = AR(I,J) - FR * ORTR(I) + FI * ORTI(I)
  97. AI(I,J) = AI(I,J) - FR * ORTI(I) - FI * ORTR(I)
  98. 120 CONTINUE
  99. C
  100. 130 CONTINUE
  101. C ********** FORM (I-(U*UT)/H)*A*(I-(U*UT)/H) **********
  102. DO 160 I = 1, IGH
  103. FR = 0.0
  104. FI = 0.0
  105. C ********** FOR J=IGH STEP -1 UNTIL M DO -- **********
  106. DO 140 JJ = M, IGH
  107. J = MP - JJ
  108. FR = FR + ORTR(J) * AR(I,J) - ORTI(J) * AI(I,J)
  109. FI = FI + ORTR(J) * AI(I,J) + ORTI(J) * AR(I,J)
  110. 140 CONTINUE
  111. C
  112. FR = FR / H
  113. FI = FI / H
  114. C
  115. DO 150 J = M, IGH
  116. AR(I,J) = AR(I,J) - FR * ORTR(J) - FI * ORTI(J)
  117. AI(I,J) = AI(I,J) + FR * ORTI(J) - FI * ORTR(J)
  118. 150 CONTINUE
  119. C
  120. 160 CONTINUE
  121. C
  122. ORTR(M) = SCALE * ORTR(M)
  123. ORTI(M) = SCALE * ORTI(M)
  124. AR(M,M-1) = -G * AR(M,M-1)
  125. AI(M,M-1) = -G * AI(M,M-1)
  126. 180 CONTINUE
  127. C
  128. 200 RETURN
  129. C ********** LAST CARD OF CORTH **********
  130. END