-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.h
More file actions
101 lines (61 loc) · 1.72 KB
/
Matrix.h
File metadata and controls
101 lines (61 loc) · 1.72 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
class Matrix{
public:
Matrix(int rows=1, int cols=3){
for (int i=0; i<rows; i++){
vector<float> row;
for (int j=0; j<cols; j++){
row.push_back(0);
}
matrix.push_back(row);
}
};
Matrix(const Matrix &m){
int rows = m.getRows();
int cols = m.getCols();
for (int i=0; i<rows; i++){
vector<float> row;
for (int j=0; j<cols; j++){
row.push_back(m.getValue(i,j));
}
matrix.push_back(row);
}
}
int getRows() const { return getNRows(); };
int getCols() const { return getNCols(); };
float getValue(int r, int c) const { return getVal(r,c); };
void setValue(int r, int c, float v) { setVal(r,c,v); };
float determinant() { return calcDeterminant(); };
Matrix inverse() { return calcInverse(); };
Matrix cofactor() { return calcCofactor(); };
Matrix adjugate() { return calcAdjugate(); };
Matrix transpose() { return calcTranspose(); };
Matrix minors() { return calcMinors(); };
Matrix checkerboard() { return performCheckerboard(); };
Matrix operator* (float x);
Matrix operator* (Matrix m);
private:
vector < vector<float> > matrix;
float getVal(int r, int c) const;
void setVal(int r, int c, float v);
int getNRows() const;
int getNCols() const;
bool validRow(int r);
bool validCol(int c);
float calcDeterminant();
Matrix calcInverse();
Matrix calcCofactor();
Matrix calcAdjugate();
Matrix calcTranspose();
Matrix calcMinors();
Matrix performCheckerboard();
float getMinor(int r, int c);
};
Matrix checkerboardMatrix(int rows, int cols);
float magnitude(Matrix m);
#endif