LAPACK 3.3.0

dsptrd.f

Go to the documentation of this file.
00001       SUBROUTINE DSPTRD( UPLO, N, AP, D, E, TAU, INFO )
00002 *
00003 *  -- LAPACK routine (version 3.2) --
00004 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00005 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       CHARACTER          UPLO
00010       INTEGER            INFO, N
00011 *     ..
00012 *     .. Array Arguments ..
00013       DOUBLE PRECISION   AP( * ), D( * ), E( * ), TAU( * )
00014 *     ..
00015 *
00016 *  Purpose
00017 *  =======
00018 *
00019 *  DSPTRD reduces a real symmetric matrix A stored in packed form to
00020 *  symmetric tridiagonal form T by an orthogonal similarity
00021 *  transformation: Q**T * A * Q = T.
00022 *
00023 *  Arguments
00024 *  =========
00025 *
00026 *  UPLO    (input) CHARACTER*1
00027 *          = 'U':  Upper triangle of A is stored;
00028 *          = 'L':  Lower triangle of A is stored.
00029 *
00030 *  N       (input) INTEGER
00031 *          The order of the matrix A.  N >= 0.
00032 *
00033 *  AP      (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2)
00034 *          On entry, the upper or lower triangle of the symmetric matrix
00035 *          A, packed columnwise in a linear array.  The j-th column of A
00036 *          is stored in the array AP as follows:
00037 *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
00038 *          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n.
00039 *          On exit, if UPLO = 'U', the diagonal and first superdiagonal
00040 *          of A are overwritten by the corresponding elements of the
00041 *          tridiagonal matrix T, and the elements above the first
00042 *          superdiagonal, with the array TAU, represent the orthogonal
00043 *          matrix Q as a product of elementary reflectors; if UPLO
00044 *          = 'L', the diagonal and first subdiagonal of A are over-
00045 *          written by the corresponding elements of the tridiagonal
00046 *          matrix T, and the elements below the first subdiagonal, with
00047 *          the array TAU, represent the orthogonal matrix Q as a product
00048 *          of elementary reflectors. See Further Details.
00049 *
00050 *  D       (output) DOUBLE PRECISION array, dimension (N)
00051 *          The diagonal elements of the tridiagonal matrix T:
00052 *          D(i) = A(i,i).
00053 *
00054 *  E       (output) DOUBLE PRECISION array, dimension (N-1)
00055 *          The off-diagonal elements of the tridiagonal matrix T:
00056 *          E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
00057 *
00058 *  TAU     (output) DOUBLE PRECISION array, dimension (N-1)
00059 *          The scalar factors of the elementary reflectors (see Further
00060 *          Details).
00061 *
00062 *  INFO    (output) INTEGER
00063 *          = 0:  successful exit
00064 *          < 0:  if INFO = -i, the i-th argument had an illegal value
00065 *
00066 *  Further Details
00067 *  ===============
00068 *
00069 *  If UPLO = 'U', the matrix Q is represented as a product of elementary
00070 *  reflectors
00071 *
00072 *     Q = H(n-1) . . . H(2) H(1).
00073 *
00074 *  Each H(i) has the form
00075 *
00076 *     H(i) = I - tau * v * v'
00077 *
00078 *  where tau is a real scalar, and v is a real vector with
00079 *  v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP,
00080 *  overwriting A(1:i-1,i+1), and tau is stored in TAU(i).
00081 *
00082 *  If UPLO = 'L', the matrix Q is represented as a product of elementary
00083 *  reflectors
00084 *
00085 *     Q = H(1) H(2) . . . H(n-1).
00086 *
00087 *  Each H(i) has the form
00088 *
00089 *     H(i) = I - tau * v * v'
00090 *
00091 *  where tau is a real scalar, and v is a real vector with
00092 *  v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP,
00093 *  overwriting A(i+2:n,i), and tau is stored in TAU(i).
00094 *
00095 *  =====================================================================
00096 *
00097 *     .. Parameters ..
00098       DOUBLE PRECISION   ONE, ZERO, HALF
00099       PARAMETER          ( ONE = 1.0D0, ZERO = 0.0D0,
00100      $                   HALF = 1.0D0 / 2.0D0 )
00101 *     ..
00102 *     .. Local Scalars ..
00103       LOGICAL            UPPER
00104       INTEGER            I, I1, I1I1, II
00105       DOUBLE PRECISION   ALPHA, TAUI
00106 *     ..
00107 *     .. External Subroutines ..
00108       EXTERNAL           DAXPY, DLARFG, DSPMV, DSPR2, XERBLA
00109 *     ..
00110 *     .. External Functions ..
00111       LOGICAL            LSAME
00112       DOUBLE PRECISION   DDOT
00113       EXTERNAL           LSAME, DDOT
00114 *     ..
00115 *     .. Executable Statements ..
00116 *
00117 *     Test the input parameters
00118 *
00119       INFO = 0
00120       UPPER = LSAME( UPLO, 'U' )
00121       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00122          INFO = -1
00123       ELSE IF( N.LT.0 ) THEN
00124          INFO = -2
00125       END IF
00126       IF( INFO.NE.0 ) THEN
00127          CALL XERBLA( 'DSPTRD', -INFO )
00128          RETURN
00129       END IF
00130 *
00131 *     Quick return if possible
00132 *
00133       IF( N.LE.0 )
00134      $   RETURN
00135 *
00136       IF( UPPER ) THEN
00137 *
00138 *        Reduce the upper triangle of A.
00139 *        I1 is the index in AP of A(1,I+1).
00140 *
00141          I1 = N*( N-1 ) / 2 + 1
00142          DO 10 I = N - 1, 1, -1
00143 *
00144 *           Generate elementary reflector H(i) = I - tau * v * v'
00145 *           to annihilate A(1:i-1,i+1)
00146 *
00147             CALL DLARFG( I, AP( I1+I-1 ), AP( I1 ), 1, TAUI )
00148             E( I ) = AP( I1+I-1 )
00149 *
00150             IF( TAUI.NE.ZERO ) THEN
00151 *
00152 *              Apply H(i) from both sides to A(1:i,1:i)
00153 *
00154                AP( I1+I-1 ) = ONE
00155 *
00156 *              Compute  y := tau * A * v  storing y in TAU(1:i)
00157 *
00158                CALL DSPMV( UPLO, I, TAUI, AP, AP( I1 ), 1, ZERO, TAU,
00159      $                     1 )
00160 *
00161 *              Compute  w := y - 1/2 * tau * (y'*v) * v
00162 *
00163                ALPHA = -HALF*TAUI*DDOT( I, TAU, 1, AP( I1 ), 1 )
00164                CALL DAXPY( I, ALPHA, AP( I1 ), 1, TAU, 1 )
00165 *
00166 *              Apply the transformation as a rank-2 update:
00167 *                 A := A - v * w' - w * v'
00168 *
00169                CALL DSPR2( UPLO, I, -ONE, AP( I1 ), 1, TAU, 1, AP )
00170 *
00171                AP( I1+I-1 ) = E( I )
00172             END IF
00173             D( I+1 ) = AP( I1+I )
00174             TAU( I ) = TAUI
00175             I1 = I1 - I
00176    10    CONTINUE
00177          D( 1 ) = AP( 1 )
00178       ELSE
00179 *
00180 *        Reduce the lower triangle of A. II is the index in AP of
00181 *        A(i,i) and I1I1 is the index of A(i+1,i+1).
00182 *
00183          II = 1
00184          DO 20 I = 1, N - 1
00185             I1I1 = II + N - I + 1
00186 *
00187 *           Generate elementary reflector H(i) = I - tau * v * v'
00188 *           to annihilate A(i+2:n,i)
00189 *
00190             CALL DLARFG( N-I, AP( II+1 ), AP( II+2 ), 1, TAUI )
00191             E( I ) = AP( II+1 )
00192 *
00193             IF( TAUI.NE.ZERO ) THEN
00194 *
00195 *              Apply H(i) from both sides to A(i+1:n,i+1:n)
00196 *
00197                AP( II+1 ) = ONE
00198 *
00199 *              Compute  y := tau * A * v  storing y in TAU(i:n-1)
00200 *
00201                CALL DSPMV( UPLO, N-I, TAUI, AP( I1I1 ), AP( II+1 ), 1,
00202      $                     ZERO, TAU( I ), 1 )
00203 *
00204 *              Compute  w := y - 1/2 * tau * (y'*v) * v
00205 *
00206                ALPHA = -HALF*TAUI*DDOT( N-I, TAU( I ), 1, AP( II+1 ),
00207      $                 1 )
00208                CALL DAXPY( N-I, ALPHA, AP( II+1 ), 1, TAU( I ), 1 )
00209 *
00210 *              Apply the transformation as a rank-2 update:
00211 *                 A := A - v * w' - w * v'
00212 *
00213                CALL DSPR2( UPLO, N-I, -ONE, AP( II+1 ), 1, TAU( I ), 1,
00214      $                     AP( I1I1 ) )
00215 *
00216                AP( II+1 ) = E( I )
00217             END IF
00218             D( I ) = AP( II )
00219             TAU( I ) = TAUI
00220             II = I1I1
00221    20    CONTINUE
00222          D( N ) = AP( II )
00223       END IF
00224 *
00225       RETURN
00226 *
00227 *     End of DSPTRD
00228 *
00229       END
 All Files Functions