-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinalg.h
More file actions
145 lines (111 loc) · 3.6 KB
/
linalg.h
File metadata and controls
145 lines (111 loc) · 3.6 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef LINALG_H
#define LINALG_H
#include <iostream>
#include <ctime>
#include <cmath>
#include <conio.h>
#include "exception"
#include "iostream"
#include "iomanip"
#include "cstring"
#include "cassert"
#include "vector"
using namespace std;
template <typename T> void FreeMem(T **matr, int n);
template <typename T> void PrintMtx(T **matr, int n);
template <typename T> void SetMtx(T **matr, int n);
template <typename T> void TransponMtx(T **matr, T **tMatr, int n);
void Get_matr(int **matr, int n, int **temp_matr, int indRow, int indCol);
int Det(int **matr, int n);
enum wVecType{
wvtRow,
wvtCol
};
class wMatrix
{
protected:
// double ** data;
vector<vector<double>> data;
int _rows;
int _columns;
public:
wMatrix(int rows, int columns);
wMatrix(vector<vector<double>> matr);
wMatrix(const wMatrix &wMatrix);
~wMatrix();
int rowLen() const;
int colLen() const;
void addRow() const;
void addCol() const;
void appendRow() const;
void appendCol() const;
void print();
string toStr(string sep = "\t") const;
void copyElementsInRow(const wMatrix &wMatrix, int i);
void copywMatrix(const wMatrix &wMatrix);
void setIt(int row, int columns, double value);
void setRow(int rNum, vector<double> row);
void setCol(int cNum, vector<double> col);
double it(int row, int columns) const;
vector<double> row(int indx);
vector<double> col(int indx);
// vector<vector<double>>& matr(){return data;}
const vector<vector<double>>& matr() const{return data;} // для константных объектов
void fillZeros();
wMatrix T();
public:
double& operator()(int row, int col);
const double& operator()(int row, int col) const; // для константных объектов
wMatrix &operator=(const wMatrix &wMatrix);
wMatrix operator+(const wMatrix &);
wMatrix operator-(const wMatrix &);
// wMatrix operator*(const wMatrix &);
wMatrix operator*(const double &);
friend wMatrix operator*(const wMatrix &Matr1, const wMatrix &Matr2);
friend istream & operator>>(istream &, wMatrix &);
friend ostream & operator<<(ostream &, const wMatrix &);
};
inline double &wMatrix::operator()(int row, int col)
{
assert(col >= 0 && col < _columns);
assert(row >= 0 && row < _rows);
return data[row][col];
}
inline const double &wMatrix::operator()(int row, int col) const
{
assert(col >= 0 && col < _columns);
assert(row >= 0 && row < _rows);
return data[row][col];
}
wMatrix operator+(const wMatrix &firstwMatrix, const wMatrix &secondwMatrix);
class wVector : public wMatrix
{
public:
wVector(int size, wVecType type = wvtRow) :
wMatrix(((type == wvtRow)?size:1),
((type == wvtCol)?size:1)),
vType(type){}
wVector(vector<double> vec, wVecType type = wvtRow) :
wMatrix(((type == wvtCol)?vec.size():1),
((type == wvtRow)?vec.size():1)
),
vType(type){
switch (type) {
case wvtRow:{
for (int rIndx = 0; rIndx < vec.size(); ++rIndx) {
data[0][rIndx] = vec[rIndx];
}
}break;
case wvtCol:{
for (int cIndx = 0; cIndx < vec.size(); ++cIndx) {
data[cIndx][0] = vec[cIndx];
}
}break;
}
}
friend wMatrix operator*(const wMatrix &Matr, const wVector &Vec);
friend wMatrix operator*(const wVector &Vec , const wMatrix &Matr);
friend wMatrix operator*(const wVector &Vec1, const wVector &Vec2);
wVecType vType;
};
#endif // LINALG_H