| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 | *DECK DULSIA      SUBROUTINE DULSIA (A, MDA, M, N, B, MDB, NB, RE, AE, KEY, MODE,     +   NP, KRANK, KSURE, RNORM, W, LW, IWORK, LIW, INFO)C***BEGIN PROLOGUE  DULSIAC***PURPOSE  Solve an underdetermined linear system of equations byC            performing an LQ factorization of the matrix usingC            Householder transformations.  Emphasis is put on detectingC            possible rank deficiency.C***LIBRARY   SLATECC***CATEGORY  D9C***TYPE      DOUBLE PRECISION (ULSIA-S, DULSIA-D)C***KEYWORDS  LINEAR LEAST SQUARES, LQ FACTORIZATION,C             UNDERDETERMINED LINEAR SYSTEMC***AUTHOR  Manteuffel, T. A., (LANL)C***DESCRIPTIONCC     DULSIA computes the minimal length solution(s) to the problem AX=BC     where A is an M by N matrix with M.LE.N and B is the M by NBC     matrix of right hand sides.  User input bounds on the uncertaintyC     in the elements of A are used to detect numerical rank deficiency.C     The algorithm employs a row and column pivot strategy toC     minimize the growth of uncertainty and round-off errors.CC     DULSIA requires (MDA+1)*N + (MDB+1)*NB + 6*M dimensioned spaceCC   ******************************************************************C   *                                                                *C   *         WARNING - All input arrays are changed on exit.        *C   *                                                                *C   ******************************************************************CC     Input.. All TYPE REAL variables are DOUBLE PRECISIONCC     A(,)          Linear coefficient matrix of AX=B, with MDA theC      MDA,M,N      actual first dimension of A in the calling program.C                   M is the row dimension (no. of EQUATIONS of theC                   problem) and N the col dimension (no. of UNKNOWNS).C                   Must have MDA.GE.M and M.LE.N.CC     B(,)          Right hand side(s), with MDB the actual firstC      MDB,NB       dimension of B in the calling program. NB is theC                   number of M by 1 right hand sides.  Since theC                   solution is returned in B, must have MDB.GE.N.  IfC                   NB = 0, B is never accessed.CC   ******************************************************************C   *                                                                *C   *         Note - Use of RE and AE are what make this             *C   *                code significantly different from               *C   *                other linear least squares solvers.             *C   *                However, the inexperienced user is              *C   *                advised to set RE=0.,AE=0.,KEY=0.               *C   *                                                                *C   ******************************************************************CC     RE(),AE(),KEYC     RE()          RE() is a vector of length N such that RE(I) isC                   the maximum relative uncertainty in row I ofC                   the matrix A. The values of RE() must be betweenC                   0 and 1. A minimum of 10*machine precision willC                   be enforced.CC     AE()          AE() is a vector of length N such that AE(I) isC                   the maximum absolute uncertainty in row I ofC                   the matrix A. The values of AE() must be greaterC                   than or equal to 0.CC     KEY           For ease of use, RE and AE may be input as eitherC                   vectors or scalars. If a scalar is input, the algo-C                   rithm will use that value for each column of A.C                   The parameter KEY indicates whether scalars orC                   vectors are being input.C                        KEY=0     RE scalar  AE scalarC                        KEY=1     RE vector  AE scalarC                        KEY=2     RE scalar  AE vectorC                        KEY=3     RE vector  AE vectorCCC     MODE          The integer MODE indicates how the routineC                   is to react if rank deficiency is detected.C                   If MODE = 0 return immediately, no solutionC                             1 compute truncated solutionC                             2 compute minimal length least squares solC                   The inexperienced user is advised to set MODE=0CC     NP            The first NP rows of A will not be interchangedC                   with other rows even though the pivot strategyC                   would suggest otherwise.C                   The inexperienced user is advised to set NP=0.CC     WORK()        A real work array dimensioned 5*M.  However, ifC                   RE or AE have been specified as vectors, dimensionC                   WORK 4*M. If both RE and AE have been specifiedC                   as vectors, dimension WORK 3*M.CC     LW            Actual dimension of WORKCC     IWORK()       Integer work array dimensioned at least N+M.CC     LIW           Actual dimension of IWORK.CCC     INFO          Is a flag which provides for the efficientC                   solution of subsequent problems involving theC                   same A but different B.C                   If INFO = 0 original callC                      INFO = 1 subsequent callsC                   On subsequent calls, the user must supply A, KRANK,C                   LW, IWORK, LIW, and the first 2*M locations of WORKC                   as output by the original call to DULSIA. MODE mustC                   be equal to the value of MODE in the original call.C                   If MODE.LT.2, only the first N locations of WORKC                   are accessed. AE, RE, KEY, and NP are not accessed.CCCCC     Output..All TYPE REAL variables are DOUBLE PRECISIONCC     A(,)          Contains the lower triangular part of the reducedC                   matrix and the transformation information. It togethC                   with the first M elements of WORK (see below)C                   completely specify the LQ factorization of A.CC     B(,)          Contains the N by NB solution matrix for X.CC     KRANK,KSURE   The numerical rank of A,  based upon the relativeC                   and absolute bounds on uncertainty, is boundedC                   above by KRANK and below by KSURE. The algorithmC                   returns a solution based on KRANK. KSURE providesC                   an indication of the precision of the rank.CC     RNORM()       Contains the Euclidean length of the NB residualC                   vectors  B(I)-AX(I), I=1,NB. If the matrix A is ofC                   full rank, then RNORM=0.0.CC     WORK()        The first M locations of WORK contain valuesC                   necessary to reproduce the HouseholderC                   transformation.CC     IWORK()       The first N locations contain the order inC                   which the columns of A were used. The nextC                   M locations contain the order in which theC                   rows of A were used.CC     INFO          Flag to indicate status of computation on completionC                  -1   Parameter error(s)C                   0 - Rank deficient, no solutionC                   1 - Rank deficient, truncated solutionC                   2 - Rank deficient, minimal length least squares solC                   3 - Numerical rank 0, zero solutionC                   4 - Rank .LT. NPC                   5 - Full rankCC***REFERENCES  T. Manteuffel, An interval analysis approach to rankC                 determination in linear least squares problems,C                 Report SAND80-0655, Sandia Laboratories, June 1980.C***ROUTINES CALLED  D1MACH, DU11US, DU12US, XERMSGC***REVISION HISTORY  (YYMMDD)C   810801  DATE WRITTENC   890831  Modified array declarations.  (WRB)C   891006  Cosmetic changes to prologue.  (WRB)C   891009  Removed unreferenced variable.  (WRB)C   891009  REVISION DATE from Version 3.2C   891214  Prologue converted to Version 4.0 format.  (BAB)C   900315  CALLs to XERROR changed to CALLs to XERMSG.  (THJ)C   900510  Fixed an error message.  (RWC)C   920501  Reformatted the REFERENCES section.  (WRB)C***END PROLOGUE  DULSIA      IMPLICIT DOUBLE PRECISION (A-H,O-Z)      DOUBLE PRECISION D1MACH      DIMENSION A(MDA,*),B(MDB,*),RE(*),AE(*),RNORM(*),W(*)      INTEGER IWORK(*)CC***FIRST EXECUTABLE STATEMENT  DULSIA      IF(INFO.LT.0 .OR. INFO.GT.1) GO TO 514      IT=INFO      INFO=-1      IF(NB.EQ.0 .AND. IT.EQ.1) GO TO 501      IF(M.LT.1) GO TO 502      IF(N.LT.1) GO TO 503      IF(N.LT.M) GO TO 504      IF(MDA.LT.M) GO TO 505      IF(LIW.LT.M+N) GO TO 506      IF(MODE.LT.0 .OR. MODE.GT.3) GO TO 515      IF(NB.EQ.0) GO TO 4      IF(NB.LT.0) GO TO 507      IF(MDB.LT.N) GO TO 508      IF(IT.EQ.0) GO TO 4      GO TO 400    4 IF(KEY.LT.0.OR.KEY.GT.3) GO TO 509      IF(KEY.EQ.0 .AND. LW.LT.5*M) GO TO 510      IF(KEY.EQ.1 .AND. LW.LT.4*M) GO TO 510      IF(KEY.EQ.2 .AND. LW.LT.4*M) GO TO 510      IF(KEY.EQ.3 .AND. LW.LT.3*M) GO TO 510      IF(NP.LT.0 .OR. NP.GT.M) GO TO 516C      EPS=10.*D1MACH(3)      M1=1      M2=M1+M      M3=M2+M      M4=M3+M      M5=M4+MC      IF(KEY.EQ.1) GO TO 100      IF(KEY.EQ.2) GO TO 200      IF(KEY.EQ.3) GO TO 300C      IF(RE(1).LT.0.D00) GO TO 511      IF(RE(1).GT.1.0D0) GO TO 512      IF(RE(1).LT.EPS) RE(1)=EPS      IF(AE(1).LT.0.0D0) GO TO 513      DO 20 I=1,M      W(M4-1+I)=RE(1)      W(M5-1+I)=AE(1)   20 CONTINUE      CALL DU11US(A,MDA,M,N,W(M4),W(M5),MODE,NP,KRANK,KSURE,     1            W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))      GO TO 400C  100 CONTINUE      IF(AE(1).LT.0.0D0) GO TO 513      DO 120 I=1,M      IF(RE(I).LT.0.0D0) GO TO 511      IF(RE(I).GT.1.0D0) GO TO 512      IF(RE(I).LT.EPS) RE(I)=EPS      W(M4-1+I)=AE(1)  120 CONTINUE      CALL DU11US(A,MDA,M,N,RE,W(M4),MODE,NP,KRANK,KSURE,     1            W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))      GO TO 400C  200 CONTINUE      IF(RE(1).LT.0.0D0) GO TO 511      IF(RE(1).GT.1.0D0) GO TO 512      IF(RE(1).LT.EPS) RE(1)=EPS      DO 220 I=1,M      W(M4-1+I)=RE(1)      IF(AE(I).LT.0.0D0) GO TO 513  220 CONTINUE      CALL DU11US(A,MDA,M,N,W(M4),AE,MODE,NP,KRANK,KSURE,     1            W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))      GO TO 400C  300 CONTINUE      DO 320 I=1,M      IF(RE(I).LT.0.0D0) GO TO 511      IF(RE(I).GT.1.0D0) GO TO 512      IF(RE(I).LT.EPS) RE(I)=EPS      IF(AE(I).LT.0.0D0) GO TO 513  320 CONTINUE      CALL DU11US(A,MDA,M,N,RE,AE,MODE,NP,KRANK,KSURE,     1            W(M1),W(M2),W(M3),IWORK(M1),IWORK(M2))CC     DETERMINE INFOC  400 IF(KRANK.NE.M) GO TO 402          INFO=5          GO TO 410  402 IF(KRANK.NE.0) GO TO 404          INFO=3          GO TO 410  404 IF(KRANK.GE.NP) GO TO 406          INFO=4          RETURN  406 INFO=MODE      IF(MODE.EQ.0) RETURN  410 IF(NB.EQ.0) RETURNCCC     SOLUTION PHASEC      M1=1      M2=M1+M      M3=M2+M      IF(INFO.EQ.2) GO TO 420      IF(LW.LT.M2-1) GO TO 510      CALL DU12US(A,MDA,M,N,B,MDB,NB,MODE,KRANK,     1            RNORM,W(M1),W(M1),IWORK(M1),IWORK(M2))      RETURNC  420 IF(LW.LT.M3-1) GO TO 510      CALL DU12US(A,MDA,M,N,B,MDB,NB,MODE,KRANK,     1            RNORM,W(M1),W(M2),IWORK(M1),IWORK(M2))      RETURNCC     ERROR MESSAGESC  501 CALL XERMSG ('SLATEC', 'DULSIA',     +   'SOLUTION ONLY (INFO=1) BUT NO RIGHT HAND SIDE (NB=0)', 1, 0)      RETURN  502 CALL XERMSG ('SLATEC', 'DULSIA', 'M.LT.1', 2, 1)      RETURN  503 CALL XERMSG ('SLATEC', 'DULSIA', 'N.LT.1', 2, 1)      RETURN  504 CALL XERMSG ('SLATEC', 'DULSIA', 'N.LT.M', 2, 1)      RETURN  505 CALL XERMSG ('SLATEC', 'DULSIA', 'MDA.LT.M', 2, 1)      RETURN  506 CALL XERMSG ('SLATEC', 'DULSIA', 'LIW.LT.M+N', 2, 1)      RETURN  507 CALL XERMSG ('SLATEC', 'DULSIA', 'NB.LT.0', 2, 1)      RETURN  508 CALL XERMSG ('SLATEC', 'DULSIA', 'MDB.LT.N', 2, 1)      RETURN  509 CALL XERMSG ('SLATEC', 'DULSIA', 'KEY OUT OF RANGE', 2, 1)      RETURN  510 CALL XERMSG ('SLATEC', 'DULSIA', 'INSUFFICIENT WORK SPACE', 8, 1)      INFO=-1      RETURN  511 CALL XERMSG ('SLATEC', 'DULSIA', 'RE(I) .LT. 0', 2, 1)      RETURN  512 CALL XERMSG ('SLATEC', 'DULSIA', 'RE(I) .GT. 1', 2, 1)      RETURN  513 CALL XERMSG ('SLATEC', 'DULSIA', 'AE(I) .LT. 0', 2, 1)      RETURN  514 CALL XERMSG ('SLATEC', 'DULSIA', 'INFO OUT OF RANGE', 2, 1)      RETURN  515 CALL XERMSG ('SLATEC', 'DULSIA', 'MODE OUT OF RANGE', 2, 1)      RETURN  516 CALL XERMSG ('SLATEC', 'DULSIA', 'NP OUT OF RANGE', 2, 1)      RETURN      END
 |