home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sources / misc / 4252 / newmat1.cxx next >
Encoding:
C/C++ Source or Header  |  1993-01-11  |  3.2 KB  |  121 lines

  1. //$$ newmat1.cxx   Matrix type functions
  2.  
  3. // Copyright (C) 1991,2,3: R B Davies
  4.  
  5.  
  6. #include "include.h"
  7.  
  8. #include "newmat.h"
  9.  
  10.  
  11.  
  12. /************************* MatrixType functions *****************************/
  13.  
  14.  
  15. MatrixType MatrixType::operator*(const MatrixType& mt) const
  16. {
  17.    int a = attribute & mt.attribute;
  18.    if ((a & (Upper+Lower)) == (Upper+Lower)) return Dg;
  19.    else return a & ~Symmetric;
  20. }
  21.  
  22. MatrixType MatrixType::t() const
  23. {
  24.    int a = attribute & ~(Upper+Lower);
  25.    if (attribute & Upper) a |= Lower;
  26.    if (attribute & Lower) a |= Upper;
  27.    return a;
  28. }
  29.  
  30. MatrixType MatrixType::MultRHS() const
  31. {
  32.    if ((attribute & (Upper+Lower)) == (Upper+Lower)) return Dg;
  33.    else return attribute & ~Symmetric;
  34. }
  35.  
  36.  
  37.  
  38. MatrixType::operator char*() const
  39. {
  40. // make a string with the name of matrix with the given attributes
  41.    switch (attribute)
  42.    {
  43.    case Valid:                              return "Rect ";
  44.    case Valid+Symmetric:                    return "Sym  ";
  45.    case Valid+Band:                         return "Band ";
  46.    case Valid+Symmetric+Band:               return "SmBnd";
  47.    case Valid+Upper:                        return "UT   ";
  48.    case Valid+Upper+Lower:
  49.    case Valid+Band+Upper+Lower:
  50.    case Valid+Symmetric+Upper:
  51.    case Valid+Symmetric+Band+Upper:
  52.    case Valid+Symmetric+Lower:
  53.    case Valid+Symmetric+Band+Lower:
  54.    case Valid+Symmetric+Upper+Lower:
  55.    case Valid+Symmetric+Band+Upper+Lower:   return "Diag ";
  56.    case Valid+Band+Upper:                   return "UpBnd";
  57.    case Valid+Lower:                        return "LT   ";
  58.    case Valid+Band+Lower:                   return "LwBnd";
  59.    default:
  60.       if (!(attribute & Valid))             return "UnSp ";
  61.       if (attribute & LUDeco)
  62.          return (attribute & Band) ?     "BndLU" : "Crout";
  63.                                             return "?????";
  64.    }
  65. }
  66.  
  67.  
  68. GeneralMatrix* MatrixType::New(int nr, int nc, BaseMatrix* bm) const
  69. {
  70. // make a new matrix with the given attributes
  71.  
  72.    Tracer tr("New"); GeneralMatrix* gm;
  73.    switch (attribute)
  74.    {
  75.    case Valid:
  76.       if (nc==1) { gm = new ColumnVector(nr); break; }
  77.       if (nr==1) { gm = new RowVector(nc); break; }
  78.       gm = new Matrix(nr, nc); break;
  79.  
  80.    case Valid+Symmetric:
  81.       gm = new SymmetricMatrix(nr); break;
  82.  
  83.    case Valid+Band:
  84.       {
  85.          MatrixBandWidth bw = bm->BandWidth();
  86.          gm = new BandMatrix(nr,bw.lower,bw.upper); break;
  87.       }
  88.  
  89.    case Valid+Symmetric+Band:
  90.       gm = new SymmetricBandMatrix(nr,bm->BandWidth().lower); break;
  91.  
  92.    case Valid+Upper:
  93.       gm = new UpperTriangularMatrix(nr); break;
  94.  
  95.    case Valid+Upper+Lower:
  96.    case Valid+Band+Upper+Lower:
  97.    case Valid+Symmetric+Upper:
  98.    case Valid+Symmetric+Band+Upper:
  99.    case Valid+Symmetric+Lower:
  100.    case Valid+Symmetric+Band+Lower:
  101.    case Valid+Symmetric+Upper+Lower:
  102.    case Valid+Symmetric+Band+Upper+Lower:
  103.       gm = new DiagonalMatrix(nr); break;
  104.  
  105.    case Valid+Band+Upper:
  106.       gm = new UpperBandMatrix(nr,bm->BandWidth().upper); break;
  107.  
  108.    case Valid+Lower:
  109.       gm = new LowerTriangularMatrix(nr); break;
  110.  
  111.    case Valid+Band+Lower:
  112.       gm = new LowerBandMatrix(nr,bm->BandWidth().lower); break;
  113.  
  114.    default:
  115.       Throw(ProgramException("Invalid matrix type"));
  116.    }
  117.    
  118.    MatrixErrorNoSpace(gm); gm->Protect(); return gm;
  119. }
  120.  
  121.