2
* matrix.h is part of Brewtarget, and is Copyright Philip G. Lee
3
* (rocketman768@gmail.com), 2009.
5
* Brewtarget is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Brewtarget is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#define EPSILON 0.00001
31
//======================Class Defns.=============================
33
class DimensionException;
34
class IncomputableException;
36
ostream& operator<<( ostream &os, const Matrix &rhs );
38
//======================Class: Matrix=============================
41
friend ostream& operator<<( ostream &os, const Matrix &rhs );
44
~Matrix(); // Destructor
45
Matrix( unsigned int rows, unsigned int cols ); // Constructor
46
Matrix( const vector<Matrix> &colVec ); // Constructor
47
Matrix( const Matrix &m, unsigned int colStart, unsigned int colEnd ); // Constructor
48
Matrix( const Matrix &rhs ); // Copy constructor
50
static Matrix getIdentity( unsigned int n ); // Gets n x n identity matrix.
52
Matrix& operator=( const Matrix &rhs );
53
Matrix& operator+=( const Matrix &rhs );
54
Matrix& operator-=( const Matrix &rhs );
55
const Matrix operator+( const Matrix &other ) const;
56
const Matrix operator-( const Matrix &other ) const;
57
const Matrix operator*( const Matrix &rhs ) const;
58
Matrix getRow( unsigned int row ) const;
59
Matrix getCol( unsigned int col ) const;
60
unsigned int getRows() const;
61
unsigned int getCols() const;
62
inline double getVal( unsigned int row, unsigned int col ) const;
63
inline void setVal( unsigned int row, unsigned int col, double val );
64
void setRow( unsigned int row, vector<double> vec );
65
void setCol( unsigned int col, vector<double> vec );
66
Matrix inverse() const;
67
bool hasInverse() const;
70
bool hasNonZeroDiags() const;
71
void swapRows( unsigned int row1, unsigned int row2 );
72
void appendCols( const Matrix& other );
80
//======================Class: DimensionException=============================
81
class DimensionException: public exception
83
virtual const char* what() const throw()
85
return "Dimensions of argument were not expected.";
89
DimensionException(unsigned int argRows, unsigned int argCols, bool rowsMatter, bool colsMatter )
93
_rowsMatter = rowsMatter;
94
_colsMatter = colsMatter;
97
bool colsMatter(){ return _colsMatter; }
98
bool rowsMatter(){ return _rowsMatter; }
99
unsigned int getArgRows(){ return _argRows; }
100
unsigned int getArgCols(){ return _argCols; }
103
unsigned int _argRows;
104
unsigned int _argCols;
109
//======================Class: IncomputableException=============================
110
class IncomputableException: public exception
112
virtual const char* what() const throw()
114
return "Could not compute what you asked.";