-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrix.h
63 lines (49 loc) · 1.7 KB
/
matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* matrix.h
*/
#ifndef __MATRIX_H__
#define __MATRIX_H__
#include <iostream>
class Matrix {
public:
Matrix(int, int);
Matrix(double**, int, int);
Matrix();
~Matrix();
Matrix(const Matrix&);
Matrix& operator=(const Matrix&);
inline double& operator()(int x, int y) { return p[x][y]; }
Matrix& operator+=(const Matrix&);
Matrix& operator-=(const Matrix&);
Matrix& operator*=(const Matrix&);
Matrix& operator*=(double);
Matrix& operator/=(double);
Matrix operator^(int);
friend std::ostream& operator<<(std::ostream&, const Matrix&);
friend std::istream& operator>>(std::istream&, Matrix&);
void swapRows(int, int);
Matrix transpose();
static Matrix createIdentity(int);
static Matrix solve(Matrix, Matrix);
static Matrix bandSolve(Matrix, Matrix, int);
// functions on vectors
static double dotProduct(Matrix, Matrix);
// functions on augmented matrices
static Matrix augment(Matrix, Matrix);
Matrix gaussianEliminate();
Matrix rowReduceFromGaussian();
void readSolutionsFromRREF(std::ostream& os);
Matrix inverse();
private:
int rows_, cols_;
double **p;
void allocSpace();
Matrix expHelper(const Matrix&, int);
};
Matrix operator+(const Matrix&, const Matrix&);
Matrix operator-(const Matrix&, const Matrix&);
Matrix operator*(const Matrix&, const Matrix&);
Matrix operator*(const Matrix&, double);
Matrix operator*(double, const Matrix&);
Matrix operator/(const Matrix&, double);
#endif