-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.h
86 lines (66 loc) · 2.71 KB
/
Matrix.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
84
85
86
/*
* Matrix.h
* The Matrix class provides the support for arbitrarily sized 2-D matrices.
* The class implement a set of functions according to the provided test file.
*
* Created on: University Collage London.
* Date: 12.2018-01.2019
* Author: student number:18043309
*/
#ifndef MATRIX_H_
#define MATRIX_H_
#include <iostream>
using namespace std;
class Matrix {
protected:
// These are the only member variables allowed!
int noOfRows;
int noOfColumns;
double *data;
//determine row-column indexing mapping to 1-D indexing
int GetIndex (const int rowIdx, const int columnIdx) const;
public:
//constructors
Matrix (const int noOfRow, const int noOfCols);//standard constructor
Matrix (const Matrix& input);//copy constructor
//destructor
virtual ~Matrix ();
//static member funtion for named constructors
static Matrix Zeros(const int noOfRows, const int noOfColumns);
static Matrix Ones(const int noOfRows, const int noOfColumns);
//assignment operator
Matrix& operator= (const Matrix& rhs);
//a member function of multiplication assignment operator
Matrix& operator*= (const Matrix& rhs);
// a non-member function but a friend for "*" operator overloading
friend Matrix operator * (const Matrix& lhs,const Matrix rhs);
//operator overloading to output the matrix
friend ostream& operator<< (ostream& out, const Matrix& matrix);
//create Toeplitz matrix
static Matrix Toeplitz(const double* column, const int noOfRows,const double* row,const int noOfColumns);
//print function
static void Print(const double* column, const int noOfRows,const int noOfColumns);
//static matrix transpose
static Matrix Transpose(const Matrix& matrix);
//non-static matrix transpose
virtual Matrix& Transpose();
//exchange rows or columns of matrices
Matrix ExchangeRows(int row1,int row2);//exchange the whole rows
Matrix ExchangeRows(int row1,int row2,int column1,int column2);//exchange partial values of the rows
Matrix ExchangeColumns(int column1,int column2);//exchange the whole columns
Matrix ExchangeColumns(int column1,int column2,int row1,int row2);//exchange partial values of the columns
//accessors
int GetEntry(int row,int column)const;//get the entries
int GetNoOfRows()const;//get the number of rows
int GetNoOfColumns()const;//get the number of columns
//The function that sets every entry to zero
Matrix& Zeros();
//The function that sets every entry to one
Matrix& Ones();
//get the product of AT*A for least square solution
double* lss_ATA(const Matrix& A);
//get the product of AT*b for least square solution
double* lss_ATB(const Matrix& A,const double* b);
Matrix& TestingInput(const double* input, const int noOfRows,const int noOfColumns);
};
#endif /* MATRIX_H_ */