CS488 PA4
Matrix.h
1 #ifndef edu_jmu_cs_Matrix_h
2 #define edu_jmu_cs_Matrix_h
3 
4 #define TOLERANCE 0.0001
5 
6 #include <cmath>
7 #include <initializer_list>
8 #include <math.h>
9 #include <stdexcept>
10 using namespace std;
11 
12 
13 // Prototypes
14 
15 // Prototype of the Matrix class (so that it can be used in
16 // the friend prototypes)
17 class Matrix;
18 
19 // Prototypes of friend functions
20 double cof(const Matrix& A, int i, int j);
21 double det(double a);
22 double det(const Matrix& A);
23 double dot(const Matrix& A, const Matrix& B);
24 Matrix identity(int size);
25 double mminor(const Matrix& A, int i, int j);
26 Matrix operator|(const Matrix& A, const Matrix& B);
27 Matrix operator+(const Matrix& A, const Matrix& B);
28 Matrix operator-(const Matrix& A, const Matrix& B);
29 Matrix operator*(const Matrix& A, const Matrix& B);
30 Matrix operator*(double k, const Matrix& A);
31 Matrix operator*(const Matrix& A, double k);
32 bool operator==(const Matrix& A, const Matrix& B);
33 bool operator!=(const Matrix& A, const Matrix& B);
34 Matrix submatrix(const Matrix& A, int i, int j);
35 Matrix trans(const Matrix& A);
36 
37 
38 
42 class Matrix {
43  protected:
47  double** values;
48 
52  int columns;
53 
57  int rows;
58 
65  void allocateMemory(int rows, int columns);
66 
70  void deallocateMemory();
71 
77  void setValues(double value);
78 
85  void setValues(const Matrix& other);
86 
93  void setValues(const double* values);
94 
101  void setValues(double** values);
102 
103  public:
107  Matrix();
108 
115  Matrix(int rows, int columns);
116 
126  Matrix(const Matrix& original);
127 
131  ~Matrix();
132 
145  friend double cof(const Matrix& A, int i, int j);
146 
153  friend double det(double a);
154 
165  friend double det(const Matrix& A);
166 
186  friend double dot(const Matrix& A, const Matrix& B);
187 
196  double get(int r, int c) const;
197 
207  double get(int i) const;
208 
221  Matrix getColumn(int c) const;
222 
228  int getColumns() const;
229 
235  int getRows() const;
236 
246  friend Matrix identity(int size);
247 
259  friend double mminor(const Matrix& A, int i, int j);
260 
281  double& operator()(int r, int c);
282 
292  double& operator()(int i);
293 
313  Matrix& operator=(std::initializer_list<double> values);
314 
327  Matrix& operator=(const Matrix& other);
328 
340  friend Matrix operator|(const Matrix& A, const Matrix& B);
341 
353  friend Matrix operator+(const Matrix& A, const Matrix& B);
354 
366  friend Matrix operator-(const Matrix& A, const Matrix& B);
367 
379  friend Matrix operator*(const Matrix& A, const Matrix& B);
380 
391  friend Matrix operator*(double k, const Matrix& A);
392 
403  friend Matrix operator*(const Matrix& A, double k);
404 
413  friend bool operator==(const Matrix& A, const Matrix& B);
414 
423  friend bool operator!=(const Matrix& A, const Matrix& B);
424 
435  friend Matrix submatrix(const Matrix& A, int i, int j);
436 
446  friend Matrix trans(const Matrix& A);
447 };
448 
449 #endif
int rows
Definition: Matrix.h:57
friend double mminor(const Matrix &A, int i, int j)
Definition: Matrix.cpp:156
friend double cof(const Matrix &A, int i, int j)
Definition: Matrix.cpp:37
friend Matrix operator|(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:207
friend Matrix submatrix(const Matrix &A, int i, int j)
Definition: Matrix.cpp:348
Definition: Matrix.h:42
friend Matrix identity(int size)
Definition: Matrix.cpp:148
friend Matrix operator+(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:231
friend Matrix operator*(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:263
friend double dot(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:90
double ** values
Definition: Matrix.h:47
friend bool operator!=(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:311
int columns
Definition: Matrix.h:52
friend bool operator==(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:298
friend Matrix trans(const Matrix &A)
Definition: Matrix.cpp:372
friend double det(double a)
Definition: Matrix.cpp:60
friend Matrix operator-(const Matrix &A, const Matrix &B)
Definition: Matrix.cpp:247