-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearAlgebra.cpp
More file actions
90 lines (69 loc) · 1.77 KB
/
Copy pathLinearAlgebra.cpp
File metadata and controls
90 lines (69 loc) · 1.77 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
#include "LinearAlgebra.h"
#include <cassert>
#include <iostream>
#include <cmath>
Matrix LinearAlgebra::multiplyMatrices(Matrix m1, Matrix m2) {
assert(m1.cols == m2.rows);
Matrix newMatrix(m1.rows, m2.cols);
double count = 0;
for (int i = 0;i < m1.rows; ++i) {
for (int j = 0;j < m2.cols; ++j) {
for (int k = 0; k < m1.cols; ++k) {
count += m1.matrix[i][k] * m2.matrix[k][j];
}
newMatrix.matrix[i][j] = count;
count = 0;
}
}
return newMatrix;
}
Matrix LinearAlgebra::addMatrices(Matrix m1, Matrix m2) {
assert(m1.rows == m2.rows && m1.cols == m2.cols);
Matrix newMatrix(m1.rows, m1.cols);
for (int i = 0; i < m1.rows; ++i) {
for (int j = 0; j < m1.cols; ++j) {
newMatrix.matrix[i][j] = m1.matrix[i][j] + m2.matrix[i][j];
}
}
return newMatrix;
}
Matrix LinearAlgebra::subtractMatrices(Matrix m1, Matrix m2) {
assert(m1.rows == m2.rows && m1.cols == m2.cols);
Matrix newMatrix(m1.rows, m1.cols);
for (int i = 0; i < m1.rows; ++i) {
for (int j = 0; j < m1.cols; ++j) {
newMatrix.matrix[i][j] = m1.matrix[i][j] - m2.matrix[i][j];
}
}
return newMatrix;
}
Matrix LinearAlgebra::scaleMatrix(Matrix m1, double scalar) {
Matrix newMatrix(m1.rows, m1.cols);
for (int i = 0; i < m1.rows; ++i) {
for (int j = 0; j < m1.cols; ++j) {
newMatrix.matrix[i][j] = scalar * m1.matrix[i][j];
}
}
return newMatrix;
}
Matrix LinearAlgebra::getIdentityMatrix(int dim) {
Matrix newMatrix(dim);
for (int i(0); i < dim; ++i) {
newMatrix.matrix[i][i] = 1;
}
return newMatrix;
}
Matrix LinearAlgebra::getHouseHolderVector(Matrix colVect, int index) {
std::cout << colVect.getVectorNorm(2);
double sign;
if (colVect.matrix[0][0] < 0) {
sign = -1;
}
else {
sign = 1;
}
return colVect;
}
//std::unique_ptr<Matrix[]> QRDecomposition() {
//
//}