Skip Navigation Links
Numerical Libraries
Linear Algebra
Differential Equations
Optimization
Samples
Skip Navigation Links
Linear Algebra
CSLapack
CSBlas
   1:  #region Translated by Jose Antonio De Santiago-Castillo.
   2:   
   3:  //Translated by Jose Antonio De Santiago-Castillo. 
   4:  //E-mail:JAntonioDeSantiago@gmail.com
   5:  //Web: www.DotNumerics.com
   6:  //
   7:  //Fortran to C# Translation.
   8:  //Translated by:
   9:  //F2CSharp Version 0.71 (November 10, 2009)
  10:  //Code Optimizations: None
  11:  //
  12:  #endregion
  13:   
  14:  using System;
  15:  using DotNumerics.FortranLibrary;
  16:   
  17:  namespace DotNumerics.CSLapack
  18:  {
  19:      /// <summary>
  20:      /// -- LAPACK routine (version 3.1) --
  21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  22:      /// November 2006
  23:      /// Purpose
  24:      /// =======
  25:      /// 
  26:      /// DTRTRS solves a triangular system of the form
  27:      /// 
  28:      /// A * X = B  or  A**T * X = B,
  29:      /// 
  30:      /// where A is a triangular matrix of order N, and B is an N-by-NRHS
  31:      /// matrix.  A check is made to verify that A is nonsingular.
  32:      /// 
  33:      ///</summary>
  34:      public class DTRTRS
  35:      {
  36:      
  37:   
  38:          #region Dependencies
  39:          
  40:          LSAME _lsame; DTRSM _dtrsm; XERBLA _xerbla; 
  41:   
  42:          #endregion
  43:   
  44:   
  45:          #region Fields
  46:          
  47:          const double ZERO = 0.0E+0; const double ONE = 1.0E+0; bool NOUNIT = false; 
  48:   
  49:          #endregion
  50:   
  51:          public DTRTRS(LSAME lsame, DTRSM dtrsm, XERBLA xerbla)
  52:          {
  53:      
  54:   
  55:              #region Set Dependencies
  56:              
  57:              this._lsame = lsame; this._dtrsm = dtrsm; this._xerbla = xerbla; 
  58:   
  59:              #endregion
  60:   
  61:          }
  62:      
  63:          public DTRTRS()
  64:          {
  65:      
  66:   
  67:              #region Dependencies (Initialization)
  68:              
  69:              LSAME lsame = new LSAME();
  70:              XERBLA xerbla = new XERBLA();
  71:              DTRSM dtrsm = new DTRSM(lsame, xerbla);
  72:   
  73:              #endregion
  74:   
  75:   
  76:              #region Set Dependencies
  77:              
  78:              this._lsame = lsame; this._dtrsm = dtrsm; this._xerbla = xerbla; 
  79:   
  80:              #endregion
  81:   
  82:          }
  83:          /// <summary>
  84:          /// Purpose
  85:          /// =======
  86:          /// 
  87:          /// DTRTRS solves a triangular system of the form
  88:          /// 
  89:          /// A * X = B  or  A**T * X = B,
  90:          /// 
  91:          /// where A is a triangular matrix of order N, and B is an N-by-NRHS
  92:          /// matrix.  A check is made to verify that A is nonsingular.
  93:          /// 
  94:          ///</summary>
  95:          /// <param name="UPLO">
  96:          /// (input) CHARACTER*1
  97:          /// = 'U':  A is upper triangular;
  98:          /// = 'L':  A is lower triangular.
  99:          ///</param>
 100:          /// <param name="TRANS">
 101:          /// (input) CHARACTER*1
 102:          /// Specifies the form of the system of equations:
 103:          /// = 'N':  A * X = B  (No transpose)
 104:          /// = 'T':  A**T * X = B  (Transpose)
 105:          /// = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
 106:          ///</param>
 107:          /// <param name="DIAG">
 108:          /// (input) CHARACTER*1
 109:          /// = 'N':  A is non-unit triangular;
 110:          /// = 'U':  A is unit triangular.
 111:          ///</param>
 112:          /// <param name="N">
 113:          /// (input) INTEGER
 114:          /// The order of the matrix A.  N .GE. 0.
 115:          ///</param>
 116:          /// <param name="NRHS">
 117:          /// (input) INTEGER
 118:          /// The number of right hand sides, i.e., the number of columns
 119:          /// of the matrix B.  NRHS .GE. 0.
 120:          ///</param>
 121:          /// <param name="A">
 122:          /// * X = B  or  A**T * X = B,
 123:          ///</param>
 124:          /// <param name="LDA">
 125:          /// (input) INTEGER
 126:          /// The leading dimension of the array A.  LDA .GE. max(1,N).
 127:          ///</param>
 128:          /// <param name="B">
 129:          /// (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
 130:          /// On entry, the right hand side matrix B.
 131:          /// On exit, if INFO = 0, the solution matrix X.
 132:          ///</param>
 133:          /// <param name="LDB">
 134:          /// (input) INTEGER
 135:          /// The leading dimension of the array B.  LDB .GE. max(1,N).
 136:          ///</param>
 137:          /// <param name="INFO">
 138:          /// (output) INTEGER
 139:          /// = 0:  successful exit
 140:          /// .LT. 0: if INFO = -i, the i-th argument had an illegal value
 141:          /// .GT. 0: if INFO = i, the i-th diagonal element of A is zero,
 142:          /// indicating that the matrix is singular and the solutions
 143:          /// X have not been computed.
 144:          ///</param>
 145:          public void Run(string UPLO, string TRANS, string DIAG, int N, int NRHS, double[] A, int offset_a
 146:                           , int LDA, ref double[] B, int offset_b, int LDB, ref int INFO)
 147:          {
 148:   
 149:              #region Array Index Correction
 150:              
 151:               int o_a = -1 - LDA + offset_a;  int o_b = -1 - LDB + offset_b; 
 152:   
 153:              #endregion
 154:   
 155:   
 156:              #region Strings
 157:              
 158:              UPLO = UPLO.Substring(0, 1);  TRANS = TRANS.Substring(0, 1);  DIAG = DIAG.Substring(0, 1);  
 159:   
 160:              #endregion
 161:   
 162:   
 163:              #region Prolog
 164:              
 165:              // *
 166:              // *  -- LAPACK routine (version 3.1) --
 167:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 168:              // *     November 2006
 169:              // *
 170:              // *     .. Scalar Arguments ..
 171:              // *     ..
 172:              // *     .. Array Arguments ..
 173:              // *     ..
 174:              // *
 175:              // *  Purpose
 176:              // *  =======
 177:              // *
 178:              // *  DTRTRS solves a triangular system of the form
 179:              // *
 180:              // *     A * X = B  or  A**T * X = B,
 181:              // *
 182:              // *  where A is a triangular matrix of order N, and B is an N-by-NRHS
 183:              // *  matrix.  A check is made to verify that A is nonsingular.
 184:              // *
 185:              // *  Arguments
 186:              // *  =========
 187:              // *
 188:              // *  UPLO    (input) CHARACTER*1
 189:              // *          = 'U':  A is upper triangular;
 190:              // *          = 'L':  A is lower triangular.
 191:              // *
 192:              // *  TRANS   (input) CHARACTER*1
 193:              // *          Specifies the form of the system of equations:
 194:              // *          = 'N':  A * X = B  (No transpose)
 195:              // *          = 'T':  A**T * X = B  (Transpose)
 196:              // *          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
 197:              // *
 198:              // *  DIAG    (input) CHARACTER*1
 199:              // *          = 'N':  A is non-unit triangular;
 200:              // *          = 'U':  A is unit triangular.
 201:              // *
 202:              // *  N       (input) INTEGER
 203:              // *          The order of the matrix A.  N >= 0.
 204:              // *
 205:              // *  NRHS    (input) INTEGER
 206:              // *          The number of right hand sides, i.e., the number of columns
 207:              // *          of the matrix B.  NRHS >= 0.
 208:              // *
 209:              // *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
 210:              // *          The triangular matrix A.  If UPLO = 'U', the leading N-by-N
 211:              // *          upper triangular part of the array A contains the upper
 212:              // *          triangular matrix, and the strictly lower triangular part of
 213:              // *          A is not referenced.  If UPLO = 'L', the leading N-by-N lower
 214:              // *          triangular part of the array A contains the lower triangular
 215:              // *          matrix, and the strictly upper triangular part of A is not
 216:              // *          referenced.  If DIAG = 'U', the diagonal elements of A are
 217:              // *          also not referenced and are assumed to be 1.
 218:              // *
 219:              // *  LDA     (input) INTEGER
 220:              // *          The leading dimension of the array A.  LDA >= max(1,N).
 221:              // *
 222:              // *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
 223:              // *          On entry, the right hand side matrix B.
 224:              // *          On exit, if INFO = 0, the solution matrix X.
 225:              // *
 226:              // *  LDB     (input) INTEGER
 227:              // *          The leading dimension of the array B.  LDB >= max(1,N).
 228:              // *
 229:              // *  INFO    (output) INTEGER
 230:              // *          = 0:  successful exit
 231:              // *          < 0: if INFO = -i, the i-th argument had an illegal value
 232:              // *          > 0: if INFO = i, the i-th diagonal element of A is zero,
 233:              // *               indicating that the matrix is singular and the solutions
 234:              // *               X have not been computed.
 235:              // *
 236:              // *  =====================================================================
 237:              // *
 238:              // *     .. Parameters ..
 239:              // *     ..
 240:              // *     .. Local Scalars ..
 241:              // *     ..
 242:              // *     .. External Functions ..
 243:              // *     ..
 244:              // *     .. External Subroutines ..
 245:              // *     ..
 246:              // *     .. Intrinsic Functions ..
 247:              //      INTRINSIC          MAX;
 248:              // *     ..
 249:              // *     .. Executable Statements ..
 250:              // *
 251:              // *     Test the input parameters.
 252:              // *
 253:   
 254:              #endregion
 255:   
 256:   
 257:              #region Body
 258:              
 259:              INFO = 0;
 260:              NOUNIT = this._lsame.Run(DIAG, "N");
 261:              if (!this._lsame.Run(UPLO, "U") && !this._lsame.Run(UPLO, "L"))
 262:              {
 263:                  INFO =  - 1;
 264:              }
 265:              else
 266:              {
 267:                  if (!this._lsame.Run(TRANS, "N") && !this._lsame.Run(TRANS, "T") && !this._lsame.Run(TRANS, "C"))
 268:                  {
 269:                      INFO =  - 2;
 270:                  }
 271:                  else
 272:                  {
 273:                      if (!NOUNIT && !this._lsame.Run(DIAG, "U"))
 274:                      {
 275:                          INFO =  - 3;
 276:                      }
 277:                      else
 278:                      {
 279:                          if (N < 0)
 280:                          {
 281:                              INFO =  - 4;
 282:                          }
 283:                          else
 284:                          {
 285:                              if (NRHS < 0)
 286:                              {
 287:                                  INFO =  - 5;
 288:                              }
 289:                              else
 290:                              {
 291:                                  if (LDA < Math.Max(1, N))
 292:                                  {
 293:                                      INFO =  - 7;
 294:                                  }
 295:                                  else
 296:                                  {
 297:                                      if (LDB < Math.Max(1, N))
 298:                                      {
 299:                                          INFO =  - 9;
 300:                                      }
 301:                                  }
 302:                              }
 303:                          }
 304:                      }
 305:                  }
 306:              }
 307:              if (INFO != 0)
 308:              {
 309:                  this._xerbla.Run("DTRTRS",  - INFO);
 310:                  return;
 311:              }
 312:              // *
 313:              // *     Quick return if possible
 314:              // *
 315:              if (N == 0) return;
 316:              // *
 317:              // *     Check for singularity.
 318:              // *
 319:              if (NOUNIT)
 320:              {
 321:                  for (INFO = 1; INFO <= N; INFO++)
 322:                  {
 323:                      if (A[INFO+INFO * LDA + o_a] == ZERO) return;
 324:                  }
 325:              }
 326:              INFO = 0;
 327:              // *
 328:              // *     Solve A * x = b  or  A' * x = b.
 329:              // *
 330:              this._dtrsm.Run("Left", UPLO, TRANS, DIAG, N, NRHS
 331:                              , ONE, A, offset_a, LDA, ref B, offset_b, LDB);
 332:              // *
 333:              return;
 334:              // *
 335:              // *     End of DTRTRS
 336:              // *
 337:   
 338:              #endregion
 339:   
 340:          }
 341:      }
 342:  }