1*> \brief \b DLAGSY 2* 3* =========== DOCUMENTATION =========== 4* 5* Online html documentation available at 6* http://www.netlib.org/lapack/explore-html/ 7* 8* Definition: 9* =========== 10* 11* SUBROUTINE DLAGSY( N, K, D, A, LDA, ISEED, WORK, INFO ) 12* 13* .. Scalar Arguments .. 14* INTEGER INFO, K, LDA, N 15* .. 16* .. Array Arguments .. 17* INTEGER ISEED( 4 ) 18* DOUBLE PRECISION A( LDA, * ), D( * ), WORK( * ) 19* .. 20* 21* 22*> \par Purpose: 23* ============= 24*> 25*> \verbatim 26*> 27*> DLAGSY generates a real symmetric matrix A, by pre- and post- 28*> multiplying a real diagonal matrix D with a random orthogonal matrix: 29*> A = U*D*U'. The semi-bandwidth may then be reduced to k by additional 30*> orthogonal transformations. 31*> \endverbatim 32* 33* Arguments: 34* ========== 35* 36*> \param[in] N 37*> \verbatim 38*> N is INTEGER 39*> The order of the matrix A. N >= 0. 40*> \endverbatim 41*> 42*> \param[in] K 43*> \verbatim 44*> K is INTEGER 45*> The number of nonzero subdiagonals within the band of A. 46*> 0 <= K <= N-1. 47*> \endverbatim 48*> 49*> \param[in] D 50*> \verbatim 51*> D is DOUBLE PRECISION array, dimension (N) 52*> The diagonal elements of the diagonal matrix D. 53*> \endverbatim 54*> 55*> \param[out] A 56*> \verbatim 57*> A is DOUBLE PRECISION array, dimension (LDA,N) 58*> The generated n by n symmetric matrix A (the full matrix is 59*> stored). 60*> \endverbatim 61*> 62*> \param[in] LDA 63*> \verbatim 64*> LDA is INTEGER 65*> The leading dimension of the array A. LDA >= N. 66*> \endverbatim 67*> 68*> \param[in,out] ISEED 69*> \verbatim 70*> ISEED is INTEGER array, dimension (4) 71*> On entry, the seed of the random number generator; the array 72*> elements must be between 0 and 4095, and ISEED(4) must be 73*> odd. 74*> On exit, the seed is updated. 75*> \endverbatim 76*> 77*> \param[out] WORK 78*> \verbatim 79*> WORK is DOUBLE PRECISION array, dimension (2*N) 80*> \endverbatim 81*> 82*> \param[out] INFO 83*> \verbatim 84*> INFO is INTEGER 85*> = 0: successful exit 86*> < 0: if INFO = -i, the i-th argument had an illegal value 87*> \endverbatim 88* 89* Authors: 90* ======== 91* 92*> \author Univ. of Tennessee 93*> \author Univ. of California Berkeley 94*> \author Univ. of Colorado Denver 95*> \author NAG Ltd. 96* 97*> \ingroup double_matgen 98* 99* ===================================================================== 100 SUBROUTINE DLAGSY( N, K, D, A, LDA, ISEED, WORK, INFO ) 101* 102* -- LAPACK auxiliary routine -- 103* -- LAPACK is a software package provided by Univ. of Tennessee, -- 104* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 105* 106* .. Scalar Arguments .. 107 INTEGER INFO, K, LDA, N 108* .. 109* .. Array Arguments .. 110 INTEGER ISEED( 4 ) 111 DOUBLE PRECISION A( LDA, * ), D( * ), WORK( * ) 112* .. 113* 114* ===================================================================== 115* 116* .. Parameters .. 117 DOUBLE PRECISION ZERO, ONE, HALF 118 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, HALF = 0.5D+0 ) 119* .. 120* .. Local Scalars .. 121 INTEGER I, J 122 DOUBLE PRECISION ALPHA, TAU, WA, WB, WN 123* .. 124* .. External Subroutines .. 125 EXTERNAL DAXPY, DGEMV, DGER, DLARNV, DSCAL, DSYMV, 126 $ DSYR2, XERBLA 127* .. 128* .. External Functions .. 129 DOUBLE PRECISION DDOT, DNRM2 130 EXTERNAL DDOT, DNRM2 131* .. 132* .. Intrinsic Functions .. 133 INTRINSIC MAX, SIGN 134* .. 135* .. Executable Statements .. 136* 137* Test the input arguments 138* 139 INFO = 0 140 IF( N.LT.0 ) THEN 141 INFO = -1 142 ELSE IF( K.LT.0 .OR. K.GT.N-1 ) THEN 143 INFO = -2 144 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 145 INFO = -5 146 END IF 147 IF( INFO.LT.0 ) THEN 148 CALL XERBLA( 'DLAGSY', -INFO ) 149 RETURN 150 END IF 151* 152* initialize lower triangle of A to diagonal matrix 153* 154 DO 20 J = 1, N 155 DO 10 I = J + 1, N 156 A( I, J ) = ZERO 157 10 CONTINUE 158 20 CONTINUE 159 DO 30 I = 1, N 160 A( I, I ) = D( I ) 161 30 CONTINUE 162* 163* Generate lower triangle of symmetric matrix 164* 165 DO 40 I = N - 1, 1, -1 166* 167* generate random reflection 168* 169 CALL DLARNV( 3, ISEED, N-I+1, WORK ) 170 WN = DNRM2( N-I+1, WORK, 1 ) 171 WA = SIGN( WN, WORK( 1 ) ) 172 IF( WN.EQ.ZERO ) THEN 173 TAU = ZERO 174 ELSE 175 WB = WORK( 1 ) + WA 176 CALL DSCAL( N-I, ONE / WB, WORK( 2 ), 1 ) 177 WORK( 1 ) = ONE 178 TAU = WB / WA 179 END IF 180* 181* apply random reflection to A(i:n,i:n) from the left 182* and the right 183* 184* compute y := tau * A * u 185* 186 CALL DSYMV( 'Lower', N-I+1, TAU, A( I, I ), LDA, WORK, 1, ZERO, 187 $ WORK( N+1 ), 1 ) 188* 189* compute v := y - 1/2 * tau * ( y, u ) * u 190* 191 ALPHA = -HALF*TAU*DDOT( N-I+1, WORK( N+1 ), 1, WORK, 1 ) 192 CALL DAXPY( N-I+1, ALPHA, WORK, 1, WORK( N+1 ), 1 ) 193* 194* apply the transformation as a rank-2 update to A(i:n,i:n) 195* 196 CALL DSYR2( 'Lower', N-I+1, -ONE, WORK, 1, WORK( N+1 ), 1, 197 $ A( I, I ), LDA ) 198 40 CONTINUE 199* 200* Reduce number of subdiagonals to K 201* 202 DO 60 I = 1, N - 1 - K 203* 204* generate reflection to annihilate A(k+i+1:n,i) 205* 206 WN = DNRM2( N-K-I+1, A( K+I, I ), 1 ) 207 WA = SIGN( WN, A( K+I, I ) ) 208 IF( WN.EQ.ZERO ) THEN 209 TAU = ZERO 210 ELSE 211 WB = A( K+I, I ) + WA 212 CALL DSCAL( N-K-I, ONE / WB, A( K+I+1, I ), 1 ) 213 A( K+I, I ) = ONE 214 TAU = WB / WA 215 END IF 216* 217* apply reflection to A(k+i:n,i+1:k+i-1) from the left 218* 219 CALL DGEMV( 'Transpose', N-K-I+1, K-1, ONE, A( K+I, I+1 ), LDA, 220 $ A( K+I, I ), 1, ZERO, WORK, 1 ) 221 CALL DGER( N-K-I+1, K-1, -TAU, A( K+I, I ), 1, WORK, 1, 222 $ A( K+I, I+1 ), LDA ) 223* 224* apply reflection to A(k+i:n,k+i:n) from the left and the right 225* 226* compute y := tau * A * u 227* 228 CALL DSYMV( 'Lower', N-K-I+1, TAU, A( K+I, K+I ), LDA, 229 $ A( K+I, I ), 1, ZERO, WORK, 1 ) 230* 231* compute v := y - 1/2 * tau * ( y, u ) * u 232* 233 ALPHA = -HALF*TAU*DDOT( N-K-I+1, WORK, 1, A( K+I, I ), 1 ) 234 CALL DAXPY( N-K-I+1, ALPHA, A( K+I, I ), 1, WORK, 1 ) 235* 236* apply symmetric rank-2 update to A(k+i:n,k+i:n) 237* 238 CALL DSYR2( 'Lower', N-K-I+1, -ONE, A( K+I, I ), 1, WORK, 1, 239 $ A( K+I, K+I ), LDA ) 240* 241 A( K+I, I ) = -WA 242 DO 50 J = K + I + 1, N 243 A( J, I ) = ZERO 244 50 CONTINUE 245 60 CONTINUE 246* 247* Store full symmetric matrix 248* 249 DO 80 J = 1, N 250 DO 70 I = J + 1, N 251 A( J, I ) = A( I, J ) 252 70 CONTINUE 253 80 CONTINUE 254 RETURN 255* 256* End of DLAGSY 257* 258 END 259