-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
61 lines (55 loc) · 1.27 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
#ifndef MATRIX_H
#define MATRIX_H
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#define MAXROWS 100
#define MAXCOLS 100
using namespace std;
class Matrix
{
public:
/* Contructor */
Matrix();
Matrix(int n, int m);
~Matrix();
/* Accessor functions */
inline void setSize(int n, int m)
{
rows = n;
cols = m;
}
inline int getRows() const
{
return rows;
}
inline int getCols() const
{
return cols;
}
inline float getValue(int n, int m) const
{
return M[n][m];
}
inline void setValue(int n, int m, float x)
{
M[n][m] = x;
}
/* Matrix Operation functions */
Matrix add(Matrix &B) const;
Matrix subtract(Matrix &B) const;
Matrix multiply(Matrix &B) const;
Matrix multiply(float c) const; /* Scalar multiplication */
Matrix inverse() const;
Matrix cofactor() const; //used for inverse
Matrix transpose() const; // used for inverse
float dot(Matrix &B, int row, int col) const;
float det() const; /* determinant */
Matrix minor1(int i,int j) const; /* used in determinant */
friend ostream& operator<<(ostream &s, Matrix &c);
private:
int rows;
int cols;
float M[MAXROWS][MAXCOLS];
};
#endif // MATRIX_H