-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAT.h
83 lines (68 loc) · 2.64 KB
/
MAT.h
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
//////MAT.cpp
//////Author: YUNG-SHAN SU
//////Date: 3/25
// matrix class
#ifndef MAT_H
#define MAT_H
#include "VEC.h"
class MAT {
private:
int n; // define nxn matrix
VEC **va; // array of n pointers to vectors
public:
MAT(int dim); // uninit constructor
MAT(const MAT &m1); // copy constructor
MAT(int dim,double *v); // init constructor
~MAT(); // destructor
int dim(); // return dimension of the matrix
MAT tpose(); // transpose
MAT &operator-(); // unary operator, negative value
MAT &operator=(MAT m1); // assignment
MAT &operator=(double a); // assignment
MAT &operator+=(MAT &m1); // m += m1;
MAT &operator-=(MAT &m1); // m -= m1;
MAT &operator*=(double a); // m *= dbl;
MAT &operator/=(double a); // m /= dbl;
MAT operator+(MAT m1); // m1 + m2
MAT operator-(MAT m1); // m1 - m2
MAT operator*(MAT m1); // m1 * m2
VEC & operator[](int m); // m'th row
VEC operator*(VEC &v1); // m x v1
MAT operator*(double a); // m * dbl
MAT operator/(double a); // m / dbl
void print();
friend MAT operator*(double a,MAT &m1); // dbl x m
friend VEC operator*(VEC &v1,MAT &m1); // vT x m
};
MAT operator*(double a,const MAT &m1); // dbl x m
VEC operator*(VEC &v1,MAT &m1); // vT x m
/////////HW2 function////////////
MAT &luFact(MAT &m1); // LU decomposition
VEC fwdSubs(MAT &m1,VEC b); // forward substitution
VEC bckSubs(MAT &m1,VEC b); // backward substitution
/////////////////////////////////
/////////HW3 function////////////
MAT getResistorNetworksMatrix(int dim); //Get the linear system network
/////////////////////////////////
////////HW4 function////////////
int jacobi(MAT &A,VEC b,VEC &x,int maxIter,double tol);
int gaussSeidel(MAT &A,VEC b,VEC &x,int maxIter,double tol);
int sgs(MAT &A,VEC b,VEC &x,int maxIter,double tol);
double one_norm(VEC &va);
double two_norm(VEC &va);
double max_norm(VEC &va);
////////HW5 function////////////
int cg(MAT &A,VEC b,VEC &x,int maxIter, double tol);
/////////HW6 function//////////////
int EVpwr(MAT &A,VEC &q0,double &lambda,double tol,int maxiter);
int EViPwr(MAT &A,VEC &q0,double &lambda,double tol,int maxiter);
int EViPwrShft(MAT &A,VEC &q0,double &lambda,double mu,double tol,int maxiter);
int QR_shift(MAT &A,VEC &lambda,double &condition_number,double mu,double tol,int maxiter);
double epson_1(double &lambda1,double &lambda2);
double epson_2(VEC &q1,VEC &q2);
double epson_3(MAT &A,VEC &q,double &lambda);
double epson_4(MAT &A,VEC &q,double &lambda);
///////HW7 function//////////////
int EVqr(MAT &A,double tol,int maxiter);
int EVqrShifted(MAT &A,double mu,double tol,int maxiter);
#endif