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:      /// DLANSB  returns the value of the one norm,  or the Frobenius norm, or
  27:      /// the  infinity norm,  or the element of  largest absolute value  of an
  28:      /// n by n symmetric band matrix A,  with k super-diagonals.
  29:      /// 
  30:      /// Description
  31:      /// ===========
  32:      /// 
  33:      /// DLANSB returns the value
  34:      /// 
  35:      /// DLANSB = ( 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 DLANSB
  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; int L = 0; double ABSA = 0; double SCALE = 0; 
  63:          double SUM = 0;double VALUE = 0; 
  64:   
  65:          #endregion
  66:   
  67:          public DLANSB(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 DLANSB()
  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:          /// DLANSB  returns the value of the one norm,  or the Frobenius norm, or
 103:          /// the  infinity norm,  or the element of  largest absolute value  of an
 104:          /// n by n symmetric band matrix A,  with k super-diagonals.
 105:          /// 
 106:          /// Description
 107:          /// ===========
 108:          /// 
 109:          /// DLANSB returns the value
 110:          /// 
 111:          /// DLANSB = ( 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 DLANSB as described
 128:          /// above.
 129:          ///</param>
 130:          /// <param name="UPLO">
 131:          /// (input) CHARACTER*1
 132:          /// Specifies whether the upper or lower triangular part of the
 133:          /// band matrix A is supplied.
 134:          /// = 'U':  Upper triangular part is supplied
 135:          /// = 'L':  Lower triangular part is supplied
 136:          ///</param>
 137:          /// <param name="N">
 138:          /// (input) INTEGER
 139:          /// The order of the matrix A.  N .GE. 0.  When N = 0, DLANSB is
 140:          /// set to zero.
 141:          ///</param>
 142:          /// <param name="K">
 143:          /// (input) INTEGER
 144:          /// The number of super-diagonals or sub-diagonals of the
 145:          /// band matrix A.  K .GE. 0.
 146:          ///</param>
 147:          /// <param name="AB">
 148:          /// (input) DOUBLE PRECISION array, dimension (LDAB,N)
 149:          /// The upper or lower triangle of the symmetric band matrix A,
 150:          /// stored in the first K+1 rows of AB.  The j-th column of A is
 151:          /// stored in the j-th column of the array AB as follows:
 152:          /// if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k).LE.i.LE.j;
 153:          /// if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j.LE.i.LE.min(n,j+k).
 154:          ///</param>
 155:          /// <param name="LDAB">
 156:          /// (input) INTEGER
 157:          /// The leading dimension of the array AB.  LDAB .GE. K+1.
 158:          ///</param>
 159:          /// <param name="WORK">
 160:          /// (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
 161:          /// where LWORK .GE. N when NORM = 'I' or '1' or 'O'; otherwise,
 162:          /// WORK is not referenced.
 163:          ///</param>
 164:          public double Run(string NORM, string UPLO, int N, int K, double[] AB, int offset_ab, int LDAB
 165:                             , ref double[] WORK, int offset_work)
 166:          {
 167:          double dlansb = 0;
 168:   
 169:              #region Array Index Correction
 170:              
 171:               int o_ab = -1 - LDAB + offset_ab;  int o_work = -1 + offset_work; 
 172:   
 173:              #endregion
 174:   
 175:   
 176:              #region Strings
 177:              
 178:              NORM = NORM.Substring(0, 1);  UPLO = UPLO.Substring(0, 1);  
 179:   
 180:              #endregion
 181:   
 182:   
 183:              #region Prolog
 184:              
 185:              // *
 186:              // *  -- LAPACK auxiliary routine (version 3.1) --
 187:              // *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 188:              // *     November 2006
 189:              // *
 190:              // *     .. Scalar Arguments ..
 191:              // *     ..
 192:              // *     .. Array Arguments ..
 193:              // *     ..
 194:              // *
 195:              // *  Purpose
 196:              // *  =======
 197:              // *
 198:              // *  DLANSB  returns the value of the one norm,  or the Frobenius norm, or
 199:              // *  the  infinity norm,  or the element of  largest absolute value  of an
 200:              // *  n by n symmetric band matrix A,  with k super-diagonals.
 201:              // *
 202:              // *  Description
 203:              // *  ===========
 204:              // *
 205:              // *  DLANSB returns the value
 206:              // *
 207:              // *     DLANSB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
 208:              // *              (
 209:              // *              ( norm1(A),         NORM = '1', 'O' or 'o'
 210:              // *              (
 211:              // *              ( normI(A),         NORM = 'I' or 'i'
 212:              // *              (
 213:              // *              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
 214:              // *
 215:              // *  where  norm1  denotes the  one norm of a matrix (maximum column sum),
 216:              // *  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
 217:              // *  normF  denotes the  Frobenius norm of a matrix (square root of sum of
 218:              // *  squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm.
 219:              // *
 220:              // *  Arguments
 221:              // *  =========
 222:              // *
 223:              // *  NORM    (input) CHARACTER*1
 224:              // *          Specifies the value to be returned in DLANSB as described
 225:              // *          above.
 226:              // *
 227:              // *  UPLO    (input) CHARACTER*1
 228:              // *          Specifies whether the upper or lower triangular part of the
 229:              // *          band matrix A is supplied.
 230:              // *          = 'U':  Upper triangular part is supplied
 231:              // *          = 'L':  Lower triangular part is supplied
 232:              // *
 233:              // *  N       (input) INTEGER
 234:              // *          The order of the matrix A.  N >= 0.  When N = 0, DLANSB is
 235:              // *          set to zero.
 236:              // *
 237:              // *  K       (input) INTEGER
 238:              // *          The number of super-diagonals or sub-diagonals of the
 239:              // *          band matrix A.  K >= 0.
 240:              // *
 241:              // *  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N)
 242:              // *          The upper or lower triangle of the symmetric band matrix A,
 243:              // *          stored in the first K+1 rows of AB.  The j-th column of A is
 244:              // *          stored in the j-th column of the array AB as follows:
 245:              // *          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
 246:              // *          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
 247:              // *
 248:              // *  LDAB    (input) INTEGER
 249:              // *          The leading dimension of the array AB.  LDAB >= K+1.
 250:              // *
 251:              // *  WORK    (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
 252:              // *          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
 253:              // *          WORK is not referenced.
 254:              // *
 255:              // * =====================================================================
 256:              // *
 257:              // *     .. Parameters ..
 258:              // *     ..
 259:              // *     .. Local Scalars ..
 260:              // *     ..
 261:              // *     .. External Subroutines ..
 262:              // *     ..
 263:              // *     .. External Functions ..
 264:              // *     ..
 265:              // *     .. Intrinsic Functions ..
 266:              //      INTRINSIC          ABS, MAX, MIN, SQRT;
 267:              // *     ..
 268:              // *     .. Executable Statements ..
 269:              // *
 270:   
 271:              #endregion
 272:   
 273:   
 274:              #region Body
 275:              
 276:              if (N == 0)
 277:              {
 278:                  VALUE = ZERO;
 279:              }
 280:              else
 281:              {
 282:                  if (this._lsame.Run(NORM, "M"))
 283:                  {
 284:                      // *
 285:                      // *        Find max(abs(A(i,j))).
 286:                      // *
 287:                      VALUE = ZERO;
 288:                      if (this._lsame.Run(UPLO, "U"))
 289:                      {
 290:                          for (J = 1; J <= N; J++)
 291:                          {
 292:                              for (I = Math.Max(K + 2 - J, 1); I <= K + 1; I++)
 293:                              {
 294:                                  VALUE = Math.Max(VALUE, Math.Abs(AB[I+J * LDAB + o_ab]));
 295:                              }
 296:                          }
 297:                      }
 298:                      else
 299:                      {
 300:                          for (J = 1; J <= N; J++)
 301:                          {
 302:                              for (I = 1; I <= Math.Min(N + 1 - J, K + 1); I++)
 303:                              {
 304:                                  VALUE = Math.Max(VALUE, Math.Abs(AB[I+J * LDAB + o_ab]));
 305:                              }
 306:                          }
 307:                      }
 308:                  }
 309:                  else
 310:                  {
 311:                      if ((this._lsame.Run(NORM, "I")) || (this._lsame.Run(NORM, "O")) || (NORM == "1"))
 312:                      {
 313:                          // *
 314:                          // *        Find normI(A) ( = norm1(A), since A is symmetric).
 315:                          // *
 316:                          VALUE = ZERO;
 317:                          if (this._lsame.Run(UPLO, "U"))
 318:                          {
 319:                              for (J = 1; J <= N; J++)
 320:                              {
 321:                                  SUM = ZERO;
 322:                                  L = K + 1 - J;
 323:                                  for (I = Math.Max(1, J - K); I <= J - 1; I++)
 324:                                  {
 325:                                      ABSA = Math.Abs(AB[L + I+J * LDAB + o_ab]);
 326:                                      SUM = SUM + ABSA;
 327:                                      WORK[I + o_work] = WORK[I + o_work] + ABSA;
 328:                                  }
 329:                                  WORK[J + o_work] = SUM + Math.Abs(AB[K + 1+J * LDAB + o_ab]);
 330:                              }
 331:                              for (I = 1; I <= N; I++)
 332:                              {
 333:                                  VALUE = Math.Max(VALUE, WORK[I + o_work]);
 334:                              }
 335:                          }
 336:                          else
 337:                          {
 338:                              for (I = 1; I <= N; I++)
 339:                              {
 340:                                  WORK[I + o_work] = ZERO;
 341:                              }
 342:                              for (J = 1; J <= N; J++)
 343:                              {
 344:                                  SUM = WORK[J + o_work] + Math.Abs(AB[1+J * LDAB + o_ab]);
 345:                                  L = 1 - J;
 346:                                  for (I = J + 1; I <= Math.Min(N, J + K); I++)
 347:                                  {
 348:                                      ABSA = Math.Abs(AB[L + I+J * LDAB + o_ab]);
 349:                                      SUM = SUM + ABSA;
 350:                                      WORK[I + o_work] = WORK[I + o_work] + ABSA;
 351:                                  }
 352:                                  VALUE = Math.Max(VALUE, SUM);
 353:                              }
 354:                          }
 355:                      }
 356:                      else
 357:                      {
 358:                          if ((this._lsame.Run(NORM, "F")) || (this._lsame.Run(NORM, "E")))
 359:                          {
 360:                              // *
 361:                              // *        Find normF(A).
 362:                              // *
 363:                              SCALE = ZERO;
 364:                              SUM = ONE;
 365:                              if (K > 0)
 366:                              {
 367:                                  if (this._lsame.Run(UPLO, "U"))
 368:                                  {
 369:                                      for (J = 2; J <= N; J++)
 370:                                      {
 371:                                          this._dlassq.Run(Math.Min(J - 1, K), AB, Math.Max(K + 2 - J, 1)+J * LDAB + o_ab, 1, ref SCALE, ref SUM);
 372:                                      }
 373:                                      L = K + 1;
 374:                                  }
 375:                                  else
 376:                                  {
 377:                                      for (J = 1; J <= N - 1; J++)
 378:                                      {
 379:                                          this._dlassq.Run(Math.Min(N - J, K), AB, 2+J * LDAB + o_ab, 1, ref SCALE, ref SUM);
 380:                                      }
 381:                                      L = 1;
 382:                                  }
 383:                                  SUM = 2 * SUM;
 384:                              }
 385:                              else
 386:                              {
 387:                                  L = 1;
 388:                              }
 389:                              this._dlassq.Run(N, AB, L+1 * LDAB + o_ab, LDAB, ref SCALE, ref SUM);
 390:                              VALUE = SCALE * Math.Sqrt(SUM);
 391:                          }
 392:                      }
 393:                  }
 394:              }
 395:              // *
 396:              dlansb = VALUE;
 397:              return dlansb;
 398:              // *
 399:              // *     End of DLANSB
 400:              // *
 401:   
 402:              #endregion
 403:   
 404:          }
 405:      }
 406:  }