# schex.f

          SUBROUTINE SCHEX (R, LDR, P, K, L, Z, LDZ, NZ, C, S, JOB)
    C***BEGIN PROLOGUE  SCHEX
    C***PURPOSE  Update the Cholesky factorization  A=TRANS(R)*R  of A
    C            positive definite matrix A of order P under diagonal
    C            permutations of the form TRANS(E)*A*E, where E is a
    C            permutation matrix.
    C***LIBRARY   SLATEC (LINPACK)
    C***CATEGORY  D7B
    C***TYPE      SINGLE PRECISION (SCHEX-S, DCHEX-D, CCHEX-C)
    C***KEYWORDS  CHOLESKY DECOMPOSITION, EXCHANGE, LINEAR ALGEBRA, LINPACK,
    C             MATRIX, POSITIVE DEFINITE
    C***AUTHOR  Stewart, G. W., (U. of Maryland)
    C***DESCRIPTION
    C
    C     SCHEX updates the Cholesky factorization
    C
    C                   A = TRANS(R)*R
    C
    C     of a positive definite matrix A of order P under diagonal
    C     permutations of the form
    C
    C                   TRANS(E)*A*E
    C
    C     where E is a permutation matrix.  Specifically, given
    C     an upper triangular matrix R and a permutation matrix
    C     E (which is specified by K, L, and JOB), SCHEX determines
    C     an orthogonal matrix U such that
    C
    C                           U*R*E = RR,
    C
    C     where RR is upper triangular.  At the users option, the
    C     transformation U will be multiplied into the array Z.
    C     If A = TRANS(X)*X, so that R is the triangular part of the
    C     QR factorization of X, then RR is the triangular part of the
    C     QR factorization of X*E, i.e., X with its columns permuted.
    C     For a less terse description of what SCHEX does and how
    C     it may be applied, see the LINPACK guide.
    C
    C     The matrix Q is determined as the product U(L-K)*...*U(1)
    C     of plane rotations of the form
    C
    C                           (    C(I)       S(I) )
    C                           (                    ) ,
    C                           (    -S(I)      C(I) )
    C
    C     where C(I) is real.  The rows these rotations operate on
    C     are described below.
    C
    C     There are two types of permutations, which are determined
    C     by the value of JOB.
    C
    C     1. Right circular shift (JOB = 1).
    C
    C         The columns are rearranged in the following order.
    C
    C                1,...,K-1,L,K,K+1,...,L-1,L+1,...,P.
    C
    C         U is the product of L-K rotations U(I), where U(I)
    C         acts in the (L-I,L-I+1)-plane.
    C
    C     2. Left circular shift (JOB = 2).
    C         The columns are rearranged in the following order
    C
    C                1,...,K-1,K+1,K+2,...,L,K,L+1,...,P.
    C
    C         U is the product of L-K rotations U(I), where U(I)
    C         acts in the (K+I-1,K+I)-plane.
    C
    C     On Entry
    C
    C         R      REAL(LDR,P), where LDR .GE. P.
    C                R contains the upper triangular factor
    C                that is to be updated.  Elements of R
    C                below the diagonal are not referenced.
    C
    C         LDR    INTEGER.
    C                LDR is the leading dimension of the array R.
    C
    C         P      INTEGER.
    C                P is the order of the matrix R.
    C
    C         K      INTEGER.
    C                K is the first column to be permuted.
    C
    C         L      INTEGER.
    C                L is the last column to be permuted.
    C                L must be strictly greater than K.
    C
    C         Z      REAL(LDZ,NZ), where LDZ.GE.P.
    C                Z is an array of NZ P-vectors into which the
    C                transformation U is multiplied.  Z is
    C                not referenced if NZ = 0.
    C
    C         LDZ    INTEGER.
    C                LDZ is the leading dimension of the array Z.
    C
    C         NZ     INTEGER.
    C                NZ is the number of columns of the matrix Z.
    C
    C         JOB    INTEGER.
    C                JOB determines the type of permutation.
    C                       JOB = 1  right circular shift.
    C                       JOB = 2  left circular shift.
    C
    C     On Return
    C
    C         R      contains the updated factor.
    C
    C         Z      contains the updated matrix Z.
    C
    C         C      REAL(P).
    C                C contains the cosines of the transforming rotations.
    C
    C         S      REAL(P).
    C                S contains the sines of the transforming rotations.
    C
    C***REFERENCES  J. J. Dongarra, J. R. Bunch, C. B. Moler, and G. W.
    C                 Stewart, LINPACK Users' Guide, SIAM, 1979.
    C***ROUTINES CALLED  SROTG
    C***REVISION HISTORY  (YYMMDD)
    C   780814  DATE WRITTEN
    C   890531  Changed all specific intrinsics to generic.  (WRB)
    C   890531  REVISION DATE from Version 3.2
    C   891214  Prologue converted to Version 4.0 format.  (BAB)
    C   900326  Removed duplicate information from DESCRIPTION section.
    C           (WRB)
    C   920501  Reformatted the REFERENCES section.  (WRB)
    C***END PROLOGUE  SCHEX