![]() |
GeneralBrokenLines
V01-11-00
|
00001 /* 00002 * VMatrix.h 00003 * 00004 * Created on: Feb 15, 2012 00005 * Author: kleinwrt 00006 */ 00007 00008 #ifndef VMATRIX_H_ 00009 #define VMATRIX_H_ 00010 00011 #include<iostream> 00012 #include <iomanip> 00013 #include<vector> 00014 #include<math.h> 00015 00017 class VVector { 00018 public: 00019 VVector(const unsigned int nRows = 0); 00020 VVector(const VVector &aVector); 00021 virtual ~VVector(); 00022 void resize(const unsigned int nRows); 00023 VVector getVec(unsigned int len, unsigned int start = 0) const; 00024 void putVec(const VVector &aVector, unsigned int start = 0); 00025 inline double &operator()(unsigned int i); 00026 inline double operator()(unsigned int i) const; 00027 unsigned int getNumRows() const; 00028 void print() const; 00029 VVector operator-(const VVector &aVector) const; 00030 private: 00031 unsigned int numRows; 00032 std::vector<double> theVec; 00033 }; 00034 00036 class VMatrix { 00037 public: 00038 VMatrix(const unsigned int nRows = 0, const unsigned int nCols = 0); 00039 VMatrix(const VMatrix &aMatrix); 00040 virtual ~VMatrix(); 00041 void resize(const unsigned int nRows, const unsigned int nCols); 00042 VMatrix transpose() const; 00043 inline double &operator()(unsigned int i, unsigned int j); 00044 inline double operator()(unsigned int i, unsigned int j) const; 00045 unsigned int getNumRows() const; 00046 unsigned int getNumCols() const; 00047 void print() const; 00048 VVector operator*(const VVector &aVector) const; 00049 VMatrix operator*(const VMatrix &aMatrix) const; 00050 VMatrix operator+(const VMatrix &aMatrix) const; 00051 private: 00052 unsigned int numRows; 00053 unsigned int numCols; 00054 std::vector<double> theVec; 00055 }; 00056 00058 class VSymMatrix { 00059 public: 00060 VSymMatrix(const unsigned int nRows = 0); 00061 virtual ~VSymMatrix(); 00062 void resize(const unsigned int nRows); 00063 unsigned int invert(); 00064 inline double &operator()(unsigned int i, unsigned int j); 00065 inline double operator()(unsigned int i, unsigned int j) const; 00066 unsigned int getNumRows() const; 00067 void print() const; 00068 VSymMatrix operator-(const VMatrix &aMatrix) const; 00069 VVector operator*(const VVector &aVector) const; 00070 VMatrix operator*(const VMatrix &aMatrix) const; 00071 private: 00072 unsigned int numRows; 00073 std::vector<double> theVec; 00074 }; 00075 00077 inline double &VMatrix::operator()(unsigned int iRow, unsigned int iCol) { 00078 return theVec[numCols * iRow + iCol]; 00079 } 00080 00082 inline double VMatrix::operator()(unsigned int iRow, unsigned int iCol) const { 00083 return theVec[numCols * iRow + iCol]; 00084 } 00085 00087 inline double &VVector::operator()(unsigned int iRow) { 00088 return theVec[iRow]; 00089 } 00090 00092 inline double VVector::operator()(unsigned int iRow) const { 00093 return theVec[iRow]; 00094 } 00095 00097 inline double &VSymMatrix::operator()(unsigned int iRow, unsigned int iCol) { 00098 return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow 00099 } 00100 00102 inline double VSymMatrix::operator()(unsigned int iRow, 00103 unsigned int iCol) const { 00104 return theVec[(iRow * iRow + iRow) / 2 + iCol]; // assuming iCol <= iRow 00105 } 00106 00107 #endif /* VMATRIX_H_ */
1.7.6.1