00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef _MATRIX_H_
00010 #define _MATRIX_H_
00011
00012 #include <iostream>
00013 using namespace std;
00014
00015 #include "MVector.h"
00016
00024 class Matrix
00025 {
00026 private:
00027
00028 int _nlines;
00029 int _ncols;
00030 vector<MVector> _lines;
00031
00032 public:
00033
00035 class Out_Of_Bounds {};
00036
00038 class Bad_Dimensions {};
00039
00048
00049 Matrix(int nl = 0, int nc = 0, double x = 0.0);
00050
00052 Matrix(MVector mv, bool transp = false);
00053
00055 operator MVector() const;
00056
00058 MVector column(int j) const;
00059
00061 MVector line(int i) const;
00062
00072 Matrix& operator+=(const Matrix& mat) {return *this = *this + mat;}
00073 Matrix& operator-=(const Matrix& mat) {return *this = *this - mat;}
00074 Matrix& operator*=(const Matrix& mat) {return *this = *this * mat;}
00075
00082
00083 int nlines() const {return _nlines;}
00085 int ncols() const {return _ncols;}
00086
00089
00090
00093 Matrix transpose() const;
00095 Matrix operator~() const {return transpose();}
00096
00101
00102 friend Matrix operator+(const Matrix& mat1, const Matrix& mat2);
00104 friend Matrix operator-(const Matrix& mat1, const Matrix& mat2);
00106 friend Matrix operator*(const Matrix& mat1, const Matrix& mat2);
00107
00114
00115 friend bool operator==(const Matrix& mat1, const Matrix& mat2);
00117 friend bool operator!=(const Matrix& mat1, const Matrix& mat2)
00118 {
00119 return ! (mat1 == mat2);
00120 }
00121
00130
00131 MVector& operator[](int i);
00133 const MVector& operator[](int i) const;
00134
00136 double& operator()(int i, int j);
00138 double operator()(int i, int j) const;
00140 double& at(int i, int j) {return (*this)(i, j);}
00142 double at(int i, int j) const {return (*this)(i, j);}
00143
00146
00147 friend ostream& operator<<(ostream& os, const Matrix& mat);
00148 };
00149
00150 #endif