-
Notifications
You must be signed in to change notification settings - Fork 1
/
Matrix.cpp
66 lines (54 loc) · 1.65 KB
/
Matrix.cpp
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
#include "Matrix.h"
using namespace std;
// Constructor
Matrix::Matrix()
{
}
my_rational Matrix::det(vector< vector< my_rational > > A)
{
return (my_rational)0;
}
void Matrix::transpose(vector< vector< my_rational > > A, vector< vector< my_rational > > At)
{
}
void Matrix::multiply(vector< vector< my_rational > > A, vector< vector< my_rational > > B, vector< vector< my_rational > > R)
{
}
void Matrix::inverse(vector< vector< my_rational > > A, vector< vector< my_rational > > Ai)
{
}
void Matrix::pivot(vector< vector< my_rational > >& B, const vector< vector< my_rational > >& A, const int& i, const int& j)
{
ldbg << "Pivoting on element: [" << i << "][" << j << "] = " << A[i][j] << "\n";
// Make sure the target matrix B holds a copy of the inital matrix A
B = A;
for (unsigned r = 0; r < A.size(); r++) {
for (unsigned s = 0; s < A[r].size(); s++) {
// We're in the row of the pivot-element. Here only devide by the value of the pivot element
if ((int)r == i) {
B[r][s] = A[r][s]/A[i][j];
continue;
}
// Otherwise bring the j'th column of this row to 0
B[r][s] = A[r][s] - A[i][s] * A[r][j]/A[i][j] ;
}
}
}
void Matrix::row_subtract(vector< vector< my_rational > >& A, const int& i, const int& j)
{
ldbg << "Subtracting: row[" << i << "] - row[" << j << "]\n";
for (unsigned s = 0; s < A[i].size(); s++) {
A[i][s] -= A[j][s];
}
}
// B = A|x
void Matrix::append_vec(vector< vector< my_rational > >& B, const vector< vector< my_rational > >& A, const vector< my_rational >& x)
{
// Copy contents of matrix A into matrix B
B = A;
// Append column x_s to Matrix B
for (unsigned i = 0; i < x.size(); i++)
{
B[i].push_back(x[i]);
}
}