Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

NEWMAT1.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NEWMAT1.CPP

Go to the documentation of this file.
00001 //Owner: Fred
00002 //$$ newmat1.cpp   Matrix type functions
00003 
00004 // Copyright (C) 1991,2,3,4: R B Davies
00005 
00006 #include "newmat.h"
00007 
00008 #ifdef use_namespace
00009 namespace NEWMAT {
00010 #endif
00011 
00012     /************************* MatrixType functions *****************************/
00013 
00014     // all operations to return MatrixTypes which correspond to valid types
00015     // of matrices.
00016     // Eg: if it has the Diagonal attribute, then it must also have
00017     // Upper, Lower, Band and Symmetric.
00018 
00019     MatrixType MatrixType::operator*(const MatrixType& mt) const {
00020         int a = attribute & mt.attribute & ~Symmetric;
00021         a |= (a & Diagonal) * 31;                     // recognise diagonal
00022         return MatrixType(a);
00023     }
00024 
00025     MatrixType MatrixType::SP(const MatrixType& mt) const {
00026         // elementwise product
00027         // Lower, Upper, Diag, Band if only one is
00028         // Symmetric, Valid (and Real) if both are
00029         // Need to include Lower & Upper => Diagonal
00030         // Will need to include both Skew => Symmetric
00031         int a = ((attribute | mt.attribute) & ~(Symmetric + Valid))
00032             | (attribute & mt.attribute);
00033         if ((a & Lower) != 0  &&  (a & Upper) != 0) a |= Diagonal;
00034         a |= (a & Diagonal) * 31;                     // recognise diagonal
00035         return MatrixType(a);
00036     }
00037 
00038     MatrixType MatrixType::i() const {              // type of inverse
00039         int a = attribute & ~(Band+LUDeco);
00040         a |= (a & Diagonal) * 31;                     // recognise diagonal
00041         return MatrixType(a);
00042     }
00043 
00044     MatrixType MatrixType::t() const {
00045         // swap lower and upper attributes
00046         // assume Upper is in bit above Lower
00047         int a = attribute;
00048         a ^= (((a >> 1) ^ a) & Lower) * 3;
00049         return MatrixType(a);
00050     }
00051 
00052     MatrixType MatrixType::MultRHS() const {
00053         // reomve symmetric attribute unless diagonal
00054         return (attribute == Dg) ? Dg : (attribute & ~Symmetric);
00055     }
00056 
00057     bool Rectangular(MatrixType a, MatrixType b, MatrixType c) {
00058         return
00059             ((a.attribute | b.attribute | c.attribute) & ~MatrixType::Valid) == 0;
00060     }
00061 
00062     char* MatrixType::Value() const {
00063         // make a string with the name of matrix with the given attributes
00064         switch (attribute) {
00065         case Valid:                              return "Rect ";
00066         case Valid+Symmetric:                    return "Sym  ";
00067         case Valid+Band:                         return "Band ";
00068         case Valid+Symmetric+Band:               return "SmBnd";
00069         case Valid+Upper:                        return "UT   ";
00070         case Valid+Diagonal+Symmetric+Band+Upper+Lower:
00071             return "Diag ";
00072         case Valid+Band+Upper:                   return "UpBnd";
00073         case Valid+Lower:                        return "LT   ";
00074         case Valid+Band+Lower:                   return "LwBnd";
00075         default:
00076             if (!(attribute & Valid))             return "UnSp ";
00077             if (attribute & LUDeco)
00078                 return (attribute & Band) ?     "BndLU" : "Crout";
00079             return "?????";
00080         }
00081     }
00082 
00083     GeneralMatrix* MatrixType::New(int nr, int nc, BaseMatrix* bm) const {
00084         // make a new matrix with the given attributes
00085 
00086         Tracer tr("New"); GeneralMatrix* gm;
00087         switch (attribute) {
00088         case Valid:
00089             if (nc==1) { gm = new ColumnVector(nr); break; }
00090             if (nr==1) { gm = new RowVector(nc); break; }
00091             gm = new Matrix(nr, nc); break;
00092 
00093         case Valid+Symmetric:
00094             gm = new SymmetricMatrix(nr); break;
00095 
00096         case Valid+Band: {
00097             MatrixBandWidth bw = bm->BandWidth();
00098             gm = new BandMatrix(nr,bw.lower,bw.upper); break;
00099         }
00100 
00101         case Valid+Symmetric+Band:
00102             gm = new SymmetricBandMatrix(nr,bm->BandWidth().lower); break;
00103 
00104         case Valid+Upper:
00105             gm = new UpperTriangularMatrix(nr); break;
00106 
00107         case Valid+Diagonal+Symmetric+Band+Upper+Lower:
00108             gm = new DiagonalMatrix(nr); break;
00109 
00110         case Valid+Band+Upper:
00111             gm = new UpperBandMatrix(nr,bm->BandWidth().upper); break;
00112 
00113         case Valid+Lower:
00114             gm = new LowerTriangularMatrix(nr); break;
00115 
00116         case Valid+Band+Lower:
00117             gm = new LowerBandMatrix(nr,bm->BandWidth().lower); break;
00118 
00119         default:
00120             Throw(ProgramException("Invalid matrix type"));
00121         }
00122 
00123         MatrixErrorNoSpace(gm); gm->Protect(); return gm;
00124     }
00125 
00126 #ifdef use_namespace
00127 }
00128 #endif

Generated on Fri Aug 23 01:37:05 2002 for VirtualU by doxygen1.2.17