1 : |
ulcessvp |
2 |
#ifndef matrix_h
|
2 : |
|
|
#define matrix_h
|
3 : |
|
|
|
4 : |
|
|
#include "intvector.h" |
5 : |
|
|
#include "doublematrix.h" |
6 : |
|
|
/**
|
7 : |
|
|
* \class Matrix
|
8 : |
ulcessvp |
13 |
* \brief This class implements a Matrix of doubles, composed of an array of nc*nr doubles
|
9 : |
ulcessvp |
2 |
*/
|
10 : |
|
|
class Matrix {
|
11 : |
|
|
public:
|
12 : |
|
|
/**
|
13 : |
ulcessvp |
13 |
* \brief This is the default Matrix constructor
|
14 : |
ulcessvp |
2 |
*/
|
15 : |
|
|
Matrix() {
|
16 : |
|
|
nrow = 0;
|
17 : |
|
|
ncol = 0;
|
18 : |
|
|
m = 0;
|
19 : |
|
|
}
|
20 : |
|
|
;
|
21 : |
|
|
/**
|
22 : |
ulcessvp |
13 |
* \brief This is the Matrix constructor for a specified size
|
23 : |
|
|
* \param nr is the length of each row of the matrix
|
24 : |
|
|
* \param nc is the length of each column of the matrix
|
25 : |
|
|
* \param initial is the initial value for all the entries of the matrix
|
26 : |
ulcessvp |
2 |
*/
|
27 : |
|
|
Matrix(int nr, int nc, double initial);
|
28 : |
|
|
/**
|
29 : |
ulcessvp |
13 |
* \brief This is the Matrix destructor
|
30 : |
|
|
* \note This will free all the memory allocated to all the elements of the matrix
|
31 : |
ulcessvp |
2 |
*/
|
32 : |
|
|
~Matrix();
|
33 : |
|
|
/**
|
34 : |
ulcessvp |
13 |
* \brief This will return the number of rows of the matrix
|
35 : |
|
|
* \return the number of rows of the matrix
|
36 : |
ulcessvp |
2 |
*/
|
37 : |
|
|
int Nrow() const {
|
38 : |
|
|
return nrow;
|
39 : |
|
|
}
|
40 : |
|
|
;
|
41 : |
|
|
/**
|
42 : |
ulcessvp |
13 |
* \brief This will return the number of columns of the matrix
|
43 : |
|
|
* \return the number of columns of the matrix
|
44 : |
ulcessvp |
2 |
*/
|
45 : |
|
|
int Ncol() const {
|
46 : |
|
|
return ncol;
|
47 : |
|
|
}
|
48 : |
|
|
;
|
49 : |
|
|
/**
|
50 : |
ulcessvp |
13 |
* \brief This will return the pointer to the row i of the matrix
|
51 : |
|
|
* \param i is the row to be returned
|
52 : |
|
|
* \return the pointer to the part of the array where the specified row begins
|
53 : |
ulcessvp |
2 |
*/
|
54 : |
ulcessvp |
13 |
double* operator [] (int i) { return m + (i*ncol); };
|
55 : |
ulcessvp |
2 |
/**
|
56 : |
ulcessvp |
13 |
* \brief This will return the pointer to the row i of the matrix
|
57 : |
|
|
* \param i is the row to be returned
|
58 : |
|
|
* \return the pointer to the part of the array where the specified row begins
|
59 : |
|
|
*/
|
60 : |
|
|
const double* operator [] (int i) const { return m + (i*ncol); };
|
61 : |
|
|
/**
|
62 : |
|
|
* \brief This will add new entries to the matrix
|
63 : |
|
|
* \param add is the number of new entries to the matrix
|
64 : |
|
|
* \param length is the number of entries to the Matrix that is created
|
65 : |
ulcessvp |
2 |
* \param value is the value that will be entered for the new entries
|
66 : |
|
|
*/
|
67 : |
|
|
void AddRows(int add, int length, double value);
|
68 : |
|
|
/**
|
69 : |
ulcessvp |
13 |
* \brief This will reset the matrix
|
70 : |
|
|
* \note This will delete every entry from the matrix and set the number of rows and columns to zero
|
71 : |
ulcessvp |
2 |
*/
|
72 : |
ulcessvp |
13 |
void Reset();
|
73 : |
ulcessvp |
2 |
/**
|
74 : |
ulcessvp |
13 |
* \brief This is will initialize the matrix to a specified size with a initial value
|
75 : |
|
|
* \param nr is the length of each row of the matrix
|
76 : |
|
|
* \param nc is the length of each column of the matrix
|
77 : |
|
|
* \param initial is the initial value for all the entries of the matrix
|
78 : |
ulcessvp |
2 |
*/
|
79 : |
ulcessvp |
5 |
void Initialize(int nr, int nc, double initial);
|
80 : |
ulcessvp |
2 |
/**
|
81 : |
ulcessvp |
13 |
* \brief This function will set all of the entries of the matrix to zero
|
82 : |
ulcessvp |
2 |
*/
|
83 : |
|
|
void setToZero();
|
84 : |
|
|
/**
|
85 : |
ulcessvp |
13 |
* \brief This function will print the data stored in the matrix
|
86 : |
ulcessvp |
2 |
* \param outfile is the ofstream that all the model information gets sent to
|
87 : |
|
|
*/
|
88 : |
|
|
void Print(ofstream& outfile) const;
|
89 : |
|
|
protected:
|
90 : |
|
|
/**
|
91 : |
ulcessvp |
13 |
* \brief This is number of rows of the matrix
|
92 : |
ulcessvp |
2 |
*/
|
93 : |
|
|
int nrow;
|
94 : |
ulcessvp |
13 |
/**
|
95 : |
|
|
* \brief This is number of columns of the matrix
|
96 : |
|
|
*/
|
97 : |
ulcessvp |
2 |
int ncol;
|
98 : |
|
|
/**
|
99 : |
ulcessvp |
13 |
* \brief This is the array of nr*nc doubles that represents the matrix
|
100 : |
ulcessvp |
2 |
*/
|
101 : |
|
|
double *m;
|
102 : |
|
|
};
|
103 : |
|
|
|
104 : |
|
|
#endif
|