-
Notifications
You must be signed in to change notification settings - Fork 1
/
Matrix.hpp
91 lines (67 loc) · 2.03 KB
/
Matrix.hpp
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
#ifndef _MATRIX_H_
#define _MATRIX_H_
#include <iostream>
#include <vector>
#include <exception>
#include <cmath>
#define zeros 0
#define identity 1
#define LL 1
#define LDL 2
enum class LUPivotType
{
NONPIVOT = (int)0,
COLPIVOT = (int)1,
ALLPIVOT = (int)2
};
enum class MatrixInitType
{
ZEROS = (int) 0,
IDENTITY = (int) 1
};
using namespace std;
/*Index of this matrix is equavalent with math expression*/
class Matrix
{
public:
unsigned int row;
unsigned int col;
vector< vector<double> > mat;
Matrix(unsigned int m, unsigned int n, double init[]);
Matrix(unsigned int m, unsigned int n, MatrixInitType type = MatrixInitType::ZEROS);
~Matrix(){};
Matrix trans();
int print();
virtual Matrix sle(Matrix b, LUPivotType LU_method = LUPivotType::COLPIVOT);
Matrix operator*(const Matrix& A);
Matrix operator-(const Matrix& B);
friend Matrix operator*(double cof, Matrix& B);
Matrix lowtri_sle(Matrix b);//function in sle(Matrix b)
Matrix uptri_sle(Matrix y);//function in sle(Matrix b)
Matrix diag_sle(Matrix b); // function for sle
virtual vector<Matrix> LU(LUPivotType method = LUPivotType::COLPIVOT);//function in sle(Matrix b)
int max_index(const vector<double>& vec);//return the index of maximum
};
class SymmetricalPositiveMatrix: public Matrix
{
public:
SymmetricalPositiveMatrix(unsigned int m, unsigned int n, double init[]);
virtual Matrix sle(Matrix b, int method=LDL);
virtual vector<Matrix> LU(int method=LDL);
};
/*principle of nominating function
* first argument is the type of number
-d:double
-s:singlo
-l:long
-i:int
*second argument is the type of matrix
-lowtri: lower triangular matrix
-uptri: upper triangular matrix
* third argument is the abbreviation of the operation
-sle: solve linear equations
*/
//Matrix lowtri_sle(unsigned int leading_dimension, double L[], double b[]);
/* It must receive an argument describing the scale of katrix
* because we can't know how long is the input number array*/
#endif