r1mpyq.f 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. *DECK R1MPYQ
  2. SUBROUTINE R1MPYQ (M, N, A, LDA, V, W)
  3. C***BEGIN PROLOGUE R1MPYQ
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to SNSQ and SNSQE
  6. C***LIBRARY SLATEC
  7. C***TYPE SINGLE PRECISION (R1MPYQ-S, D1MPYQ-D)
  8. C***AUTHOR (UNKNOWN)
  9. C***DESCRIPTION
  10. C
  11. C Given an M by N matrix A, this subroutine computes A*Q where
  12. C Q is the product of 2*(N - 1) transformations
  13. C
  14. C GV(N-1)*...*GV(1)*GW(1)*...*GW(N-1)
  15. C
  16. C and GV(I), GW(I) are Givens rotations in the (I,N) plane which
  17. C eliminate elements in the I-th and N-th planes, respectively.
  18. C Q itself is not given, rather the information to recover the
  19. C GV, GW rotations is supplied.
  20. C
  21. C The subroutine statement is
  22. C
  23. C SUBROUTINE R1MPYQ(M,N,A,LDA,V,W)
  24. C
  25. C where
  26. C
  27. C M is a positive integer input variable set to the number
  28. C of rows of A.
  29. C
  30. C N is a positive integer input variable set to the number
  31. C of columns of A.
  32. C
  33. C A is an M by N ARRAY. On input A must contain the matrix
  34. C to be postmultiplied by the orthogonal matrix Q
  35. C described above. On output A*Q has replaced A.
  36. C
  37. C LDA is a positive integer input variable not less than M
  38. C which specifies the leading dimension of the array A.
  39. C
  40. C V is an input array of length N. V(I) must contain the
  41. C information necessary to recover the Givens rotation GV(I)
  42. C described above.
  43. C
  44. C W is an input array of length N. W(I) must contain the
  45. C information necessary to recover the Givens rotation GW(I)
  46. C described above.
  47. C
  48. C***SEE ALSO SNSQ, SNSQE
  49. C***ROUTINES CALLED (NONE)
  50. C***REVISION HISTORY (YYMMDD)
  51. C 800301 DATE WRITTEN
  52. C 890831 Modified array declarations. (WRB)
  53. C 891214 Prologue converted to Version 4.0 format. (BAB)
  54. C 900326 Removed duplicate information from DESCRIPTION section.
  55. C (WRB)
  56. C 900328 Added TYPE section. (WRB)
  57. C***END PROLOGUE R1MPYQ
  58. INTEGER M,N,LDA
  59. REAL A(LDA,*),V(*),W(*)
  60. INTEGER I,J,NMJ,NM1
  61. REAL COS,ONE,SIN,TEMP
  62. SAVE ONE
  63. DATA ONE /1.0E0/
  64. C***FIRST EXECUTABLE STATEMENT R1MPYQ
  65. NM1 = N - 1
  66. IF (NM1 .LT. 1) GO TO 50
  67. DO 20 NMJ = 1, NM1
  68. J = N - NMJ
  69. IF (ABS(V(J)) .GT. ONE) COS = ONE/V(J)
  70. IF (ABS(V(J)) .GT. ONE) SIN = SQRT(ONE-COS**2)
  71. IF (ABS(V(J)) .LE. ONE) SIN = V(J)
  72. IF (ABS(V(J)) .LE. ONE) COS = SQRT(ONE-SIN**2)
  73. DO 10 I = 1, M
  74. TEMP = COS*A(I,J) - SIN*A(I,N)
  75. A(I,N) = SIN*A(I,J) + COS*A(I,N)
  76. A(I,J) = TEMP
  77. 10 CONTINUE
  78. 20 CONTINUE
  79. C
  80. C APPLY THE SECOND SET OF GIVENS ROTATIONS TO A.
  81. C
  82. DO 40 J = 1, NM1
  83. IF (ABS(W(J)) .GT. ONE) COS = ONE/W(J)
  84. IF (ABS(W(J)) .GT. ONE) SIN = SQRT(ONE-COS**2)
  85. IF (ABS(W(J)) .LE. ONE) SIN = W(J)
  86. IF (ABS(W(J)) .LE. ONE) COS = SQRT(ONE-SIN**2)
  87. DO 30 I = 1, M
  88. TEMP = COS*A(I,J) + SIN*A(I,N)
  89. A(I,N) = -SIN*A(I,J) + COS*A(I,N)
  90. A(I,J) = TEMP
  91. 30 CONTINUE
  92. 40 CONTINUE
  93. 50 CONTINUE
  94. RETURN
  95. C
  96. C LAST CARD OF SUBROUTINE R1MPYQ.
  97. C
  98. END