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 driver routine (version 3.1) --
  21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  22:      /// November 2006
  23:      /// Purpose
  24:      /// =======
  25:      /// 
  26:      /// DGESV computes the solution to a real system of linear equations
  27:      /// A * X = B,
  28:      /// where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
  29:      /// 
  30:      /// The LU decomposition with partial pivoting and row interchanges is
  31:      /// used to factor A as
  32:      /// A = P * L * U,
  33:      /// where P is a permutation matrix, L is unit lower triangular, and U is
  34:      /// upper triangular.  The factored form of A is then used to solve the
  35:      /// system of equations A * X = B.
  36:      /// 
  37:      ///</summary>
  38:      public class DGESV
  39:      {
  40:      
  41:   
  42:          #region Dependencies
  43:          
  44:          DGETRF _dgetrf; DGETRS _dgetrs; XERBLA _xerbla; 
  45:   
  46:          #endregion
  47:   
  48:          public DGESV(DGETRF dgetrf, DGETRS dgetrs, XERBLA xerbla)
  49:          {
  50:      
  51:   
  52:              #region Set Dependencies
  53:              
  54:              this._dgetrf = dgetrf; this._dgetrs = dgetrs; this._xerbla = xerbla; 
  55:   
  56:              #endregion
  57:   
  58:          }
  59:      
  60:          public DGESV()
  61:          {
  62:      
  63:   
  64:              #region Dependencies (Initialization)
  65:              
  66:              LSAME lsame = new LSAME();
  67:              XERBLA xerbla = new XERBLA();
  68:              DLAMC3 dlamc3 = new DLAMC3();
  69:              IDAMAX idamax = new IDAMAX();
  70:              DSCAL dscal = new DSCAL();
  71:              DSWAP dswap = new DSWAP();
  72:              DLASWP dlaswp = new DLASWP();
  73:              IEEECK ieeeck = new IEEECK();
  74:              IPARMQ iparmq = new IPARMQ();
  75:              DGEMM dgemm = new DGEMM(lsame, xerbla);
  76:              DLAMC1 dlamc1 = new DLAMC1(dlamc3);
  77:              DLAMC4 dlamc4 = new DLAMC4(dlamc3);
  78:              DLAMC5 dlamc5 = new DLAMC5(dlamc3);
  79:              DLAMC2 dlamc2 = new DLAMC2(dlamc3, dlamc1, dlamc4, dlamc5);
  80:              DLAMCH dlamch = new DLAMCH(lsame, dlamc2);
  81:              DGER dger = new DGER(xerbla);
  82:              DGETF2 dgetf2 = new DGETF2(dlamch, idamax, dger, dscal, dswap, xerbla);
  83:              DTRSM dtrsm = new DTRSM(lsame, xerbla);
  84:              ILAENV ilaenv = new ILAENV(ieeeck, iparmq);
  85:              DGETRF dgetrf = new DGETRF(dgemm, dgetf2, dlaswp, dtrsm, xerbla, ilaenv);
  86:              DGETRS dgetrs = new DGETRS(lsame, dlaswp, dtrsm, xerbla);
  87:   
  88:              #endregion
  89:   
  90:   
  91:              #region Set Dependencies
  92:              
  93:              this._dgetrf = dgetrf; this._dgetrs = dgetrs; this._xerbla = xerbla; 
  94:   
  95:              #endregion
  96:   
  97:          }
  98:          /// <summary>
  99:          /// Purpose
 100:          /// =======
 101:          /// 
 102:          /// DGESV computes the solution to a real system of linear equations
 103:          /// A * X = B,
 104:          /// where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
 105:          /// 
 106:          /// The LU decomposition with partial pivoting and row interchanges is
 107:          /// used to factor A as
 108:          /// A = P * L * U,
 109:          /// where P is a permutation matrix, L is unit lower triangular, and U is
 110:          /// upper triangular.  The factored form of A is then used to solve the
 111:          /// system of equations A * X = B.
 112:          /// 
 113:          ///</summary>
 114:          /// <param name="N">
 115:          /// (input) INTEGER
 116:          /// The number of linear equations, i.e., the order of the
 117:          /// matrix A.  N .GE. 0.
 118:          ///</param>
 119:          /// <param name="NRHS">
 120:          /// (input) INTEGER
 121:          /// The number of right hand sides, i.e., the number of columns
 122:          /// of the matrix B.  NRHS .GE. 0.
 123:          ///</param>
 124:          /// <param name="A">
 125:          /// (input/output) DOUBLE PRECISION array, dimension (LDA,N)
 126:          /// On entry, the N-by-N coefficient matrix A.
 127:          /// On exit, the factors L and U from the factorization
 128:          /// A = P*L*U; the unit diagonal elements of L are not stored.
 129:          ///</param>
 130:          /// <param name="LDA">
 131:          /// (input) INTEGER
 132:          /// The leading dimension of the array A.  LDA .GE. max(1,N).
 133:          ///</param>
 134:          /// <param name="IPIV">
 135:          /// (output) INTEGER array, dimension (N)
 136:          /// The pivot indices that define the permutation matrix P;
 137:          /// row i of the matrix was interchanged with row IPIV(i).
 138:          ///</param>
 139:          /// <param name="B">
 140:          /// (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
 141:          /// On entry, the N-by-NRHS matrix of right hand side matrix B.
 142:          /// On exit, if INFO = 0, the N-by-NRHS solution matrix X.
 143:          ///</param>
 144:          /// <param name="LDB">
 145:          /// (input) INTEGER
 146:          /// The leading dimension of the array B.  LDB .GE. max(1,N).
 147:          ///</param>
 148:          /// <param name="INFO">
 149:          /// (output) INTEGER
 150:          /// = 0:  successful exit
 151:          /// .LT. 0:  if INFO = -i, the i-th argument had an illegal value
 152:          /// .GT. 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
 153:          /// has been completed, but the factor U is exactly
 154:          /// singular, so the solution could not be computed.
 155:          ///</param>
 156:          public void Run(int N, int NRHS, ref double[] A, int offset_a, int LDA, ref int[] IPIV, int offset_ipiv, ref double[] B, int offset_b
 157:                           , int LDB, ref int INFO)
 158:          {
 159:   
 160:              #region Array Index Correction
 161:              
 162:               int o_a = -1 - LDA + offset_a;  int o_ipiv = -1 + offset_ipiv;  int o_b = -1 - LDB + offset_b; 
 163:   
 164:              #endregion
 165:   
 166:   
 167:              #region Prolog
 168:              
 169:              // *
 170:              // *  -- LAPACK driver routine (version 3.1) --
 171:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 172:              // *     November 2006
 173:              // *
 174:              // *     .. Scalar Arguments ..
 175:              // *     ..
 176:              // *     .. Array Arguments ..
 177:              // *     ..
 178:              // *
 179:              // *  Purpose
 180:              // *  =======
 181:              // *
 182:              // *  DGESV computes the solution to a real system of linear equations
 183:              // *     A * X = B,
 184:              // *  where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
 185:              // *
 186:              // *  The LU decomposition with partial pivoting and row interchanges is
 187:              // *  used to factor A as
 188:              // *     A = P * L * U,
 189:              // *  where P is a permutation matrix, L is unit lower triangular, and U is
 190:              // *  upper triangular.  The factored form of A is then used to solve the
 191:              // *  system of equations A * X = B.
 192:              // *
 193:              // *  Arguments
 194:              // *  =========
 195:              // *
 196:              // *  N       (input) INTEGER
 197:              // *          The number of linear equations, i.e., the order of the
 198:              // *          matrix A.  N >= 0.
 199:              // *
 200:              // *  NRHS    (input) INTEGER
 201:              // *          The number of right hand sides, i.e., the number of columns
 202:              // *          of the matrix B.  NRHS >= 0.
 203:              // *
 204:              // *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
 205:              // *          On entry, the N-by-N coefficient matrix A.
 206:              // *          On exit, the factors L and U from the factorization
 207:              // *          A = P*L*U; the unit diagonal elements of L are not stored.
 208:              // *
 209:              // *  LDA     (input) INTEGER
 210:              // *          The leading dimension of the array A.  LDA >= max(1,N).
 211:              // *
 212:              // *  IPIV    (output) INTEGER array, dimension (N)
 213:              // *          The pivot indices that define the permutation matrix P;
 214:              // *          row i of the matrix was interchanged with row IPIV(i).
 215:              // *
 216:              // *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS)
 217:              // *          On entry, the N-by-NRHS matrix of right hand side matrix B.
 218:              // *          On exit, if INFO = 0, the N-by-NRHS solution matrix X.
 219:              // *
 220:              // *  LDB     (input) INTEGER
 221:              // *          The leading dimension of the array B.  LDB >= max(1,N).
 222:              // *
 223:              // *  INFO    (output) INTEGER
 224:              // *          = 0:  successful exit
 225:              // *          < 0:  if INFO = -i, the i-th argument had an illegal value
 226:              // *          > 0:  if INFO = i, U(i,i) is exactly zero.  The factorization
 227:              // *                has been completed, but the factor U is exactly
 228:              // *                singular, so the solution could not be computed.
 229:              // *
 230:              // *  =====================================================================
 231:              // *
 232:              // *     .. External Subroutines ..
 233:              // *     ..
 234:              // *     .. Intrinsic Functions ..
 235:              //      INTRINSIC          MAX;
 236:              // *     ..
 237:              // *     .. Executable Statements ..
 238:              // *
 239:              // *     Test the input parameters.
 240:              // *
 241:   
 242:              #endregion
 243:   
 244:   
 245:              #region Body
 246:              
 247:              INFO = 0;
 248:              if (N < 0)
 249:              {
 250:                  INFO =  - 1;
 251:              }
 252:              else
 253:              {
 254:                  if (NRHS < 0)
 255:                  {
 256:                      INFO =  - 2;
 257:                  }
 258:                  else
 259:                  {
 260:                      if (LDA < Math.Max(1, N))
 261:                      {
 262:                          INFO =  - 4;
 263:                      }
 264:                      else
 265:                      {
 266:                          if (LDB < Math.Max(1, N))
 267:                          {
 268:                              INFO =  - 7;
 269:                          }
 270:                      }
 271:                  }
 272:              }
 273:              if (INFO != 0)
 274:              {
 275:                  this._xerbla.Run("DGESV ",  - INFO);
 276:                  return;
 277:              }
 278:              // *
 279:              // *     Compute the LU factorization of A.
 280:              // *
 281:              this._dgetrf.Run(N, N, ref A, offset_a, LDA, ref IPIV, offset_ipiv, ref INFO);
 282:              if (INFO == 0)
 283:              {
 284:                  // *
 285:                  // *        Solve the system A*X = B, overwriting B with X.
 286:                  // *
 287:                  this._dgetrs.Run("No transpose", N, NRHS, A, offset_a, LDA, IPIV, offset_ipiv
 288:                                   , ref B, offset_b, LDB, ref INFO);
 289:              }
 290:              return;
 291:              // *
 292:              // *     End of DGESV
 293:              // *
 294:   
 295:              #endregion
 296:   
 297:          }
 298:      }
 299:  }