-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.cpp
42 lines (37 loc) · 828 Bytes
/
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
#include "matrix.h"
Matrix setMatrix(unsigned rows, unsigned cols)
{
Matrix output(rows);
for (unsigned i = 0; i < rows; i++)
{
output[i].resize(cols);
std::fill(begin(output[i]), end(output[i]), 0);
}
return output;
}
void divide_row(Matrix &matrix, int row, double divider)
{
int n = matrix.size();
for (int i = 0; i < n + 1; i++)
{
matrix[row][i] /= divider;
}
}
void add_row(Matrix &matrix, int row_to, int row_what, double multiplier)
{
int n = matrix.size();
for (int i = 0; i < n + 1; i++)
{
matrix[row_to][i] += multiplier*matrix[row_what][i];
}
}
double sum_row(Matrix &matrix, int row)
{
int n = matrix.size();
double sum = 0;
for (int i = 0; i <= n; i++)
{
sum += matrix[row][i];
}
return sum;
}