#include <Matrix.h>
Inherited by Vector.
|
double | cof (const Matrix &A, int i, int j) |
|
double | det (double a) |
|
double | det (const Matrix &A) |
|
double | dot (const Matrix &A, const Matrix &B) |
|
Matrix | identity (int size) |
|
double | mminor (const Matrix &A, int i, int j) |
|
Matrix | operator| (const Matrix &A, const Matrix &B) |
|
Matrix | operator+ (const Matrix &A, const Matrix &B) |
|
Matrix | operator- (const Matrix &A, const Matrix &B) |
|
Matrix | operator* (const Matrix &A, const Matrix &B) |
|
Matrix | operator* (double k, const Matrix &A) |
|
Matrix | operator* (const Matrix &A, double k) |
|
bool | operator== (const Matrix &A, const Matrix &B) |
|
bool | operator!= (const Matrix &A, const Matrix &B) |
|
Matrix | submatrix (const Matrix &A, int i, int j) |
|
Matrix | trans (const Matrix &A) |
|
An encapsulation of a Matrix.
◆ Matrix() [1/3]
Default Constructor (constructs a 2x2 Matrix).
◆ Matrix() [2/3]
Matrix::Matrix |
( |
int |
rows, |
|
|
int |
columns |
|
) |
| |
Explicit Value Constructor.
- Parameters
-
rows | The number of rows |
columns | The number of columns |
◆ Matrix() [3/3]
Matrix::Matrix |
( |
const Matrix & |
original | ) |
|
A copy constructor.
Note: A copy constructor is critical because without on we can't pass a Matrix by value (which requires that it be possible to make a copy).
- Parameters
-
◆ ~Matrix()
◆ allocateMemory()
void Matrix::allocateMemory |
( |
int |
rows, |
|
|
int |
columns |
|
) |
| |
|
protected |
Allocate memory for this Matrix.
- Parameters
-
rows | The number of rows |
columns | The number of columns |
◆ deallocateMemory()
void Matrix::deallocateMemory |
( |
| ) |
|
|
protected |
Deallocate the memory used by this Matrix
◆ get() [1/2]
double Matrix::get |
( |
int |
r, |
|
|
int |
c |
|
) |
| const |
Get a particular element of this Matrix.
- Parameters
-
r | The row index |
c | The column index |
- Exceptions
-
out_of_range | if r or c are out of bounds |
- Returns
- The value of the element
◆ get() [2/2]
double Matrix::get |
( |
int |
i | ) |
const |
Get a particular element of this Matrix if it contains a single row or single column.
- Parameters
-
- Exceptions
-
out_of_range | if i is out of bounds |
length_error | if this is neither a single row nor single column |
- Returns
- The value of the element
◆ getColumn()
Matrix Matrix::getColumn |
( |
int |
c | ) |
const |
Get a column of this Matrix.
Note: This is not an efficient method, and it would be much better to use rows rather than columns (since we are using row-major ordering). However, this is more consistent with the mathematical treatment in most books.
- Parameters
-
c | The index of the column (0-based) |
- Exceptions
-
out_of_range | if c is out of bounds |
- Returns
- The column at the given index
◆ getColumns()
int Matrix::getColumns |
( |
| ) |
const |
Get the number of columns in this Matrix.
- Returns
- The number of columns
◆ getRows()
int Matrix::getRows |
( |
| ) |
const |
Get the number of rows in this Matrix.
- Returns
- The number of rows
◆ operator()() [1/2]
double & Matrix::operator() |
( |
int |
r, |
|
|
int |
c |
|
) |
| |
Access an element of this Matrix using the function-call operator.
Note: This method returns by reference so that this operator can be used on the left side of the assignment operator. Though this can be dangerous in general (since the value being referred to may not always exist), in this case it shouldn't cause any problems.
Examples of use:
- Parameters
-
r | The row index |
c | The column index |
- Exceptions
-
out_of_range | if r or c are out of bounds |
- Returns
- The value of the element
◆ operator()() [2/2]
double & Matrix::operator() |
( |
int |
i | ) |
|
Access a particular element of this Matrix using the function call operator if it contains a single row or single column.
- Parameters
-
- Exceptions
-
out_of_range | if i is out of bounds |
length_error | if this is neither a single row nor single column |
- Returns
- The the element
◆ operator=() [1/2]
Matrix & Matrix::operator= |
( |
std::initializer_list< double > |
values | ) |
|
Assign an initializer_list to this Matrix.
Example of use:
y = {1, 2, 3,
4, 5, 6,
7, 8, 9};
Note: This method is not void so that one can write x = y = {1, 2} (which first assigns {1, 2} to y and then assigns the result of that assignment to x). It returns the result by reference because there is no concern that this will not refer to something.
- Parameters
-
values | The initializer_list containing the values |
- Exceptions
-
length_error | if the list is the wrong size |
- Returns
- The Matrix referred to by this
◆ operator=() [2/2]
Assign another Matrix to this Matrix.
Note: This method is not void so that one can write x = y = z (which first assigns z to y and then assigns the result of that assignment to x). It returns the result by reference because there is no concern that this will not refer to something.
- Parameters
-
- Exceptions
-
length_error | if the shapes don't conform |
- Returns
- The Matrix referred to by this
◆ setValues() [1/4]
void Matrix::setValues |
( |
double |
value | ) |
|
|
protected |
Set the value of all elements in this Matrix to the given value.
- Parameters
-
value | The value to assign to every element |
◆ setValues() [2/4]
void Matrix::setValues |
( |
const Matrix & |
other | ) |
|
|
protected |
Set the value of all elements in this Matrix to the value of the corresponding elements in another Matrix.
- Parameters
-
◆ setValues() [3/4]
void Matrix::setValues |
( |
const double * |
values | ) |
|
|
protected |
Set the value of each element in this Matrix to the value of the corresponding element in a row-major array.
- Parameters
-
values | A pointer to the row-major array |
◆ setValues() [4/4]
void Matrix::setValues |
( |
double ** |
values | ) |
|
|
protected |
Set the value of each element in this Matrix to the value of the corresponding element in a "two-dimensional" array.
- Parameters
-
values | A pointer to the "two-dimensional" array |
◆ cof
double cof |
( |
const Matrix & |
A, |
|
|
int |
i, |
|
|
int |
j |
|
) |
| |
|
friend |
Calculate the cofactor of a square matrix (i.e., the signed determinate of the matrix with row i and column j removed).
- Parameters
-
A | The matrix (which must be square) |
i | The index of the row to exclude |
j | The index of the column to exclude |
- Exceptions
-
length_error | if the Matrix isn't square |
out_of_range | if i or j are out of bounds |
- Returns
- The cofactor
◆ det [1/2]
Calculate the determinant of a scalar.
- Parameters
-
- Returns
- The determinant of a (which is just a)
◆ det [2/2]
double det |
( |
const Matrix & |
A | ) |
|
|
friend |
Calculate the determinant of a square matrix.
Note: This implementation is not efficient since it explicitly creates each of the minors. However, it is easy to understand.
- Parameters
-
A | The matrix (which must be square) |
- Exceptions
-
length_error | if the Matrix is smaller than 2x2 or isn't square |
- Returns
- The value of the determinant
◆ dot
Calculate the dot product (more commonly known as the scalar product) of two Matrixes.
Note: While the steps in this calculation are the same as in matrix multiplication (of a 1xn and nx1 Matrix), the result is a scalar, not a Matrix. Hence, the need for this method.
We could return (trans(A)*B).get(0,0) but this would create two matrices needlessly.
This function is in the Matrix class, rather than the Vector class, because it is sometimes used with Matrixes
- Parameters
-
- Exceptions
-
length_error | if the sizes don't conform |
- Returns
- The dot product
◆ identity
Create and return an identity matrix.
Note: This function must return by value because the result Matrix is a local variable.
- Parameters
-
size | The number of rows == columns in the (square) matrix |
- Returns
- An identity Matrix
◆ mminor
double mminor |
( |
const Matrix & |
A, |
|
|
int |
i, |
|
|
int |
j |
|
) |
| |
|
friend |
Calculate the minor (i.e., the determinant of the submatrix formed by deleting a row and column).
- Parameters
-
A | The matrix (which must be square) |
i | The index of the row to exclude |
j | The index of the column to exclude |
- Exceptions
-
out_of_range | if i or j is out of bounds |
length_error | if A isn't square |
- Returns
- The minor
◆ operator!=
Compare two matrices to see if they have different elements.
- Parameters
-
A | The first matrix |
B | The second matrix |
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- true if they have any different elements; false otherwise
◆ operator* [1/3]
Multiply two matrices
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
A | The first matrix (m x n) |
B | The second matrix (n x s) |
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- \( \mathbf{A} \mathbf{B} \) [which is (m x s)]
◆ operator* [2/3]
Multiply a scalar and a matrix.
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
- Returns
- \( k \mathbf{A} \)
◆ operator* [3/3]
Multiply a matrix and a scalar.
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
- Returns
- \( \mathbf{A} k \)
◆ operator+
Add the Matrix A and the Matrix B.
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- \( \mathbf{A} + \mathbf{B} \)
◆ operator-
Subtract another Matrix from this matrix (component by component).
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- \( \mathbf{A} - \mathbf{B} \)
◆ operator==
Compare two matrices to see if they have identical elements
- Parameters
-
A | The first matrix |
B | The second matrix |
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- true or false
◆ operator|
Concatenate the columns of Matrix A and the columns Matrix B.
Note: This method must return by value because the result Matrix is a local variable.
- Parameters
-
- Exceptions
-
length_error | if the shapes of A and B do not conform |
- Returns
- \( \mathbf{A} | \mathbf{B} \)
◆ submatrix
Remove a row and column from a matrix.
- Parameters
-
A | The matrix |
i | The index of the row to exclude |
j | The index of the col to exclude |
- Exceptions
-
length_error | the Matrix is smaller than 2x2 |
out_of_range | if i or j are out of bounds |
- Returns
- The submatrix (i.e., a with row i and column j excluded)
◆ trans
Create and return a transposed version of a given matrix.
Note: This function must return by value because the result Matrix is a local variable.
- Parameters
-
- Returns
- \( \mathbf{A}^T \)
◆ columns
The number of rows in this Matrix.
◆ rows
The number of columnd in this Matrix.
◆ values
The documentation for this class was generated from the following files: