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 auxiliary routine (version 3.1) --
  21:      /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  22:      /// November 2006
  23:      /// Purpose
  24:      /// =======
  25:      /// 
  26:      /// DLANGE  returns the value of the one norm,  or the Frobenius norm, or
  27:      /// the  infinity norm,  or the  element of  largest absolute value  of a
  28:      /// real matrix A.
  29:      /// 
  30:      /// Description
  31:      /// ===========
  32:      /// 
  33:      /// DLANGE returns the value
  34:      /// 
  35:      /// DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
  36:      /// (
  37:      /// ( norm1(A),         NORM = '1', 'O' or 'o'
  38:      /// (
  39:      /// ( normI(A),         NORM = 'I' or 'i'
  40:      /// (
  41:      /// ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
  42:      /// 
  43:      /// where  norm1  denotes the  one norm of a matrix (maximum column sum),
  44:      /// normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
  45:      /// normF  denotes the  Frobenius norm of a matrix (square root of sum of
  46:      /// squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
  47:      /// 
  48:      ///</summary>
  49:      public class DLANGE
  50:      {
  51:      
  52:   
  53:          #region Dependencies
  54:          
  55:          DLASSQ _dlassq; LSAME _lsame; 
  56:   
  57:          #endregion
  58:   
  59:   
  60:          #region Fields
  61:          
  62:          const double ONE = 1.0E+0; const double ZERO = 0.0E+0; int I = 0; int J = 0; double SCALE = 0; double SUM = 0; 
  63:          double VALUE = 0;
  64:   
  65:          #endregion
  66:   
  67:          public DLANGE(DLASSQ dlassq, LSAME lsame)
  68:          {
  69:      
  70:   
  71:              #region Set Dependencies
  72:              
  73:              this._dlassq = dlassq; this._lsame = lsame; 
  74:   
  75:              #endregion
  76:   
  77:          }
  78:      
  79:          public DLANGE()
  80:          {
  81:      
  82:   
  83:              #region Dependencies (Initialization)
  84:              
  85:              DLASSQ dlassq = new DLASSQ();
  86:              LSAME lsame = new LSAME();
  87:   
  88:              #endregion
  89:   
  90:   
  91:              #region Set Dependencies
  92:              
  93:              this._dlassq = dlassq; this._lsame = lsame; 
  94:   
  95:              #endregion
  96:   
  97:          }
  98:          /// <summary>
  99:          /// Purpose
 100:          /// =======
 101:          /// 
 102:          /// DLANGE  returns the value of the one norm,  or the Frobenius norm, or
 103:          /// the  infinity norm,  or the  element of  largest absolute value  of a
 104:          /// real matrix A.
 105:          /// 
 106:          /// Description
 107:          /// ===========
 108:          /// 
 109:          /// DLANGE returns the value
 110:          /// 
 111:          /// DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
 112:          /// (
 113:          /// ( norm1(A),         NORM = '1', 'O' or 'o'
 114:          /// (
 115:          /// ( normI(A),         NORM = 'I' or 'i'
 116:          /// (
 117:          /// ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
 118:          /// 
 119:          /// where  norm1  denotes the  one norm of a matrix (maximum column sum),
 120:          /// normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
 121:          /// normF  denotes the  Frobenius norm of a matrix (square root of sum of
 122:          /// squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
 123:          /// 
 124:          ///</summary>
 125:          /// <param name="NORM">
 126:          /// (input) CHARACTER*1
 127:          /// Specifies the value to be returned in DLANGE as described
 128:          /// above.
 129:          ///</param>
 130:          /// <param name="M">
 131:          /// (input) INTEGER
 132:          /// The number of rows of the matrix A.  M .GE. 0.  When M = 0,
 133:          /// DLANGE is set to zero.
 134:          ///</param>
 135:          /// <param name="N">
 136:          /// (input) INTEGER
 137:          /// The number of columns of the matrix A.  N .GE. 0.  When N = 0,
 138:          /// DLANGE is set to zero.
 139:          ///</param>
 140:          /// <param name="A">
 141:          /// (input) DOUBLE PRECISION array, dimension (LDA,N)
 142:          /// The m by n matrix A.
 143:          ///</param>
 144:          /// <param name="LDA">
 145:          /// (input) INTEGER
 146:          /// The leading dimension of the array A.  LDA .GE. max(M,1).
 147:          ///</param>
 148:          /// <param name="WORK">
 149:          /// (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
 150:          /// where LWORK .GE. M when NORM = 'I'; otherwise, WORK is not
 151:          /// referenced.
 152:          ///</param>
 153:          public double Run(string NORM, int M, int N, double[] A, int offset_a, int LDA, ref double[] WORK, int offset_work)
 154:          {
 155:          double dlange = 0;
 156:   
 157:              #region Array Index Correction
 158:              
 159:               int o_a = -1 - LDA + offset_a;  int o_work = -1 + offset_work; 
 160:   
 161:              #endregion
 162:   
 163:   
 164:              #region Strings
 165:              
 166:              NORM = NORM.Substring(0, 1);  
 167:   
 168:              #endregion
 169:   
 170:   
 171:              #region Prolog
 172:              
 173:              // *
 174:              // *  -- LAPACK auxiliary routine (version 3.1) --
 175:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 176:              // *     November 2006
 177:              // *
 178:              // *     .. Scalar Arguments ..
 179:              // *     ..
 180:              // *     .. Array Arguments ..
 181:              // *     ..
 182:              // *
 183:              // *  Purpose
 184:              // *  =======
 185:              // *
 186:              // *  DLANGE  returns the value of the one norm,  or the Frobenius norm, or
 187:              // *  the  infinity norm,  or the  element of  largest absolute value  of a
 188:              // *  real matrix A.
 189:              // *
 190:              // *  Description
 191:              // *  ===========
 192:              // *
 193:              // *  DLANGE returns the value
 194:              // *
 195:              // *     DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
 196:              // *              (
 197:              // *              ( norm1(A),         NORM = '1', 'O' or 'o'
 198:              // *              (
 199:              // *              ( normI(A),         NORM = 'I' or 'i'
 200:              // *              (
 201:              // *              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
 202:              // *
 203:              // *  where  norm1  denotes the  one norm of a matrix (maximum column sum),
 204:              // *  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
 205:              // *  normF  denotes the  Frobenius norm of a matrix (square root of sum of
 206:              // *  squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
 207:              // *
 208:              // *  Arguments
 209:              // *  =========
 210:              // *
 211:              // *  NORM    (input) CHARACTER*1
 212:              // *          Specifies the value to be returned in DLANGE as described
 213:              // *          above.
 214:              // *
 215:              // *  M       (input) INTEGER
 216:              // *          The number of rows of the matrix A.  M >= 0.  When M = 0,
 217:              // *          DLANGE is set to zero.
 218:              // *
 219:              // *  N       (input) INTEGER
 220:              // *          The number of columns of the matrix A.  N >= 0.  When N = 0,
 221:              // *          DLANGE is set to zero.
 222:              // *
 223:              // *  A       (input) DOUBLE PRECISION array, dimension (LDA,N)
 224:              // *          The m by n matrix A.
 225:              // *
 226:              // *  LDA     (input) INTEGER
 227:              // *          The leading dimension of the array A.  LDA >= max(M,1).
 228:              // *
 229:              // *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
 230:              // *          where LWORK >= M when NORM = 'I'; otherwise, WORK is not
 231:              // *          referenced.
 232:              // *
 233:              // * =====================================================================
 234:              // *
 235:              // *     .. Parameters ..
 236:              // *     ..
 237:              // *     .. Local Scalars ..
 238:              // *     ..
 239:              // *     .. External Subroutines ..
 240:              // *     ..
 241:              // *     .. External Functions ..
 242:              // *     ..
 243:              // *     .. Intrinsic Functions ..
 244:              //      INTRINSIC          ABS, MAX, MIN, SQRT;
 245:              // *     ..
 246:              // *     .. Executable Statements ..
 247:              // *
 248:   
 249:              #endregion
 250:   
 251:   
 252:              #region Body
 253:              
 254:              if (Math.Min(M, N) == 0)
 255:              {
 256:                  VALUE = ZERO;
 257:              }
 258:              else
 259:              {
 260:                  if (this._lsame.Run(NORM, "M"))
 261:                  {
 262:                      // *
 263:                      // *        Find max(abs(A(i,j))).
 264:                      // *
 265:                      VALUE = ZERO;
 266:                      for (J = 1; J <= N; J++)
 267:                      {
 268:                          for (I = 1; I <= M; I++)
 269:                          {
 270:                              VALUE = Math.Max(VALUE, Math.Abs(A[I+J * LDA + o_a]));
 271:                          }
 272:                      }
 273:                  }
 274:                  else
 275:                  {
 276:                      if ((this._lsame.Run(NORM, "O")) || (NORM == "1"))
 277:                      {
 278:                          // *
 279:                          // *        Find norm1(A).
 280:                          // *
 281:                          VALUE = ZERO;
 282:                          for (J = 1; J <= N; J++)
 283:                          {
 284:                              SUM = ZERO;
 285:                              for (I = 1; I <= M; I++)
 286:                              {
 287:                                  SUM = SUM + Math.Abs(A[I+J * LDA + o_a]);
 288:                              }
 289:                              VALUE = Math.Max(VALUE, SUM);
 290:                          }
 291:                      }
 292:                      else
 293:                      {
 294:                          if (this._lsame.Run(NORM, "I"))
 295:                          {
 296:                              // *
 297:                              // *        Find normI(A).
 298:                              // *
 299:                              for (I = 1; I <= M; I++)
 300:                              {
 301:                                  WORK[I + o_work] = ZERO;
 302:                              }
 303:                              for (J = 1; J <= N; J++)
 304:                              {
 305:                                  for (I = 1; I <= M; I++)
 306:                                  {
 307:                                      WORK[I + o_work] = WORK[I + o_work] + Math.Abs(A[I+J * LDA + o_a]);
 308:                                  }
 309:                              }
 310:                              VALUE = ZERO;
 311:                              for (I = 1; I <= M; I++)
 312:                              {
 313:                                  VALUE = Math.Max(VALUE, WORK[I + o_work]);
 314:                              }
 315:                          }
 316:                          else
 317:                          {
 318:                              if ((this._lsame.Run(NORM, "F")) || (this._lsame.Run(NORM, "E")))
 319:                              {
 320:                                  // *
 321:                                  // *        Find normF(A).
 322:                                  // *
 323:                                  SCALE = ZERO;
 324:                                  SUM = ONE;
 325:                                  for (J = 1; J <= N; J++)
 326:                                  {
 327:                                      this._dlassq.Run(M, A, 1+J * LDA + o_a, 1, ref SCALE, ref SUM);
 328:                                  }
 329:                                  VALUE = SCALE * Math.Sqrt(SUM);
 330:                              }
 331:                          }
 332:                      }
 333:                  }
 334:              }
 335:              // *
 336:              dlange = VALUE;
 337:              return dlange;
 338:              // *
 339:              // *     End of DLANGE
 340:              // *
 341:   
 342:              #endregion
 343:   
 344:          }
 345:      }
 346:  }