#include <Matrix.h>
Public Member Functions | |
| Matrix (Integer rows=0, Integer cols=0) | |
| Default constructor. | |
| Matrix (Const Matrix &m) | |
| Copy constructor. | |
| Void | SetSize (Integer rows, Integer cols) |
| Set the size of a matrix. | |
| List< Type > & | operator[] (Integer index) |
| Indexing operator for matrix. | |
| Matrix & | operator= (Const Matrix &m) |
| Assignment/copy operator for matrix. | |
| Bool | operator== (Const Matrix &m) |
| Equality of two matrices. | |
| Bool | operator!= (Const Matrix &m) |
| Inequality of two matrices. | |
| Const Matrix | operator+ (Const Matrix &m) |
| Add two identical matrices. | |
| Const Matrix | operator- (Const Matrix &m) |
| Subtract two identical matrices. | |
| Const Matrix | operator * (Const Integer R) |
| Multiply matrix by a constant Integer. | |
| Const Matrix | operator * (Const Real R) |
| Multiply matrix by a constant Real. | |
| Const Matrix | operator+ (Const Integer R) |
| Add constant Integer to matrix. | |
| Const Matrix | operator+ (Const Real R) |
| Add constant Real to matrix. | |
| Const Matrix | operator- (Const Integer R) |
| Subtract constant Integer from matrix. | |
| Const Matrix | operator- (Const Real R) |
| Subtract constant Real from matrix. | |
| Const Matrix | operator * (Matrix &m) |
| Matrix multiplication. Columns of first matrix must be same size as rows of second. | |
| Void | print (String s=0) |
| Print a row of a matrix. | |
| Type | rows () |
| Return the number of rows in the Matrix. | |
| Type | cols () |
| Return the number of columns in the Matrix. | |
| Void | length (Integer &r, Integer &c) |
| Return the number of rows and columns in the Matrix by reference. | |
Friends | |
| ostream & | operator<< (ostream &os, Const Matrix &m) |
| Print a matrix to stdout. | |
| istream & | operator>> (istream &is, Matrix &m) |
| Scan a matrix from stdin. | |
Definition at line 28 of file Matrix.h.
Default constructor.
Definition at line 51 of file Matrix.h.
References Matrix< Type >::cols(), Matrix< Type >::rows(), and Matrix< Type >::SetSize().
Copy constructor.
Definition at line 56 of file Matrix.h.
References Matrix< Type >::SetSize().
00056 : m_matrix(NULL) { 00057 SetSize(m.m_lenRow, m.m_lenCol); 00058 for (Integer r=0; r < m_lenRow; r++) 00059 m_matrix[r]=List<Type>(m.m_matrix[r]); 00060 }
| Type Matrix< Type >::cols | ( | ) | [inline] |
Return the number of columns in the Matrix.
Definition at line 222 of file Matrix.h.
References Return.
Referenced by Matrix< Type >::length(), and Matrix< Type >::Matrix().
00222 { Return m_lenCol; }
Return the number of rows and columns in the Matrix by reference.
| r | Number of rows, returned by reference | |
| c | Number of columns, returned by reference |
Definition at line 227 of file Matrix.h.
References Matrix< Type >::cols(), and Matrix< Type >::rows().
Matrix multiplication. Columns of first matrix must be same size as rows of second.
Definition at line 194 of file Matrix.h.
References Matrix< Type >::m_lenCol, Matrix< Type >::m_lenRow, and Return.
00194 { 00195 assert(m_lenCol==m.m_lenRow); 00196 Matrix newMatrix(m_lenRow,m.m_lenCol); 00197 for (Integer r = 0; r < m_lenRow; r++) { 00198 for (Integer c = 0; c < m.m_lenCol; c++) { 00199 for (Integer i = 0; i < m_lenCol; i++) { 00200 newMatrix[r][c]+= m_matrix[r][i] * m[i][c]; 00201 } 00202 } 00203 } 00204 Return newMatrix; 00205 }
Add two identical matrices.
Performs element-by-element addition
Definition at line 119 of file Matrix.h.
References And, For, and Return.
00119 { 00120 assert(m_lenCol == m.m_lenCol And m_lenRow == m.m_lenRow); 00121 Matrix newMatrix(m_lenRow, m_lenCol); 00122 For (Integer r=0; r < m_lenRow; r++) 00123 for (Integer c=0; c < m_lenCol;c++) 00124 newMatrix[r][c] = m_matrix[r][c] + m.m_matrix[r][c]; 00125 Return newMatrix; 00126 }
Subtract two identical matrices.
Performs element-by-element subtraction
Definition at line 130 of file Matrix.h.
References And, For, and Return.
00130 { 00131 assert(m_lenCol == m.m_lenCol And m_lenRow == m.m_lenRow); 00132 Matrix newMatrix(m_lenRow, m_lenCol); 00133 For (Integer r = 0; r < m_lenRow; r++) 00134 for (Integer c = 0; c < m_lenCol; c++) 00135 newMatrix[r][c] = m_matrix[r][c] - m.m_matrix[r][c]; 00136 Return newMatrix; 00137 }
Assignment/copy operator for matrix.
Definition at line 88 of file Matrix.h.
References If, Return, and Matrix< Type >::SetSize().
00088 { 00089 If (this == &m) 00090 Return *this; 00091 SetSize(m.m_lenRow, m.m_lenCol); 00092 for (Integer r=0; r < m_lenRow; r++) { 00093 m_matrix[r] = List<Type>(m.m_matrix[r]); 00094 } 00095 Return *this; 00096 }
Equality of two matrices.
Definition at line 99 of file Matrix.h.
References False, For, If, Return, and True.
00099 { 00100 // Must have same dimensions 00101 If (m_lenRow != m.m_lenRow || m_lenCol != m.m_lenCol) 00102 Return False; 00103 00104 // All rows must match 00105 For (Integer r=0; r < m_lenRow; r++) { 00106 If (m_matrix[r] != m.m_matrix[r]) 00107 Return False; 00108 } 00109 Return( True ); 00110 }
| Type Matrix< Type >::rows | ( | ) | [inline] |
Return the number of rows in the Matrix.
Definition at line 219 of file Matrix.h.
References Return.
Referenced by Matrix< Type >::length(), and Matrix< Type >::Matrix().
00219 { Return m_lenRow; }
Set the size of a matrix.
| rows | Number of rows | |
| cols | Number of columns |
Definition at line 65 of file Matrix.h.
Referenced by Matrix< Type >::Matrix(), and Matrix< Type >::operator=().
00065 { 00066 If (m_matrix != 0) { 00067 delete[] m_matrix; 00068 m_matrix = 0; 00069 } 00070 If (cols > 0 And rows > 0) { 00071 m_matrix = new List<Type>[rows]; 00072 for (Integer i = 0; i < rows; i++) 00073 m_matrix[i].SetListSize(cols); 00074 } 00075 Else 00076 rows = 0; 00077 m_lenCol = cols; 00078 m_lenRow = rows; 00079 }
| ostream& operator<< | ( | ostream & | os, | |
| Const Matrix< Type > & | m | |||
| ) | [friend] |
| istream& operator>> | ( | istream & | is, | |
| Matrix< Type > & | m | |||
| ) | [friend] |
1.4.7