#include <Matrix.h>
|
double | cof (const Matrix &A, int i, int j) |
|
double | det (const Matrix &A) |
|
Matrix | identity (int size) |
|
double | mminor (const Matrix &A, int i, int j) |
|
Matrix | multiply (const Vector &a, const Vector &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) |
|
Vector | operator* (const Vector &v, const Matrix &M) |
|
Vector | operator* (const Matrix &M, const Vector &v) |
|
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]
Matrix::Matrix |
( |
int |
rows, |
|
|
int |
columns |
|
) |
| |
A constructor that does not allow for initial values (i.e., that initializes all elements to 0.0). The Matrix must be initialized with the assignment operator.
Example of use:
- Parameters
-
rows | The number of rows |
columns | The number of columns |
◆ Matrix() [2/3]
Matrix::Matrix |
( |
const Matrix & |
original | ) |
|
A copy constructor.
Note: A copy constructor is critical because without one we can't pass a Matrix by value (which requires that it be possible to make a copy).
- Parameters
-
◆ Matrix() [3/3]
Matrix::Matrix |
( |
const Vector & |
v | ) |
|
|
explicit |
Construct a Matrix from a Vector.
The resulting Matrix will be eithe nx1 or 1xn depending on the orientation of the Vector
- Parameters
-
◆ ~Matrix()
◆ allocateMemory()
void Matrix::allocateMemory |
( |
| ) |
|
|
protected |
Allocate memory for this Matrix.
◆ deallocateMemory()
void Matrix::deallocateMemory |
( |
| ) |
|
|
protected |
Deallocate the memory used by this Matrix.
◆ get()
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
◆ 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()()
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=() [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 values is of 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 do not conform |
- Returns
- The Matrix referred to by this
◆ setSize()
void Matrix::setSize |
( |
int |
rows, |
|
|
int |
columns |
|
) |
| |
|
protected |
Set the size of this Matrix. Note: This method should only be called by constructors.
- Parameters
-
rows | The number of rows |
columns | The number of columns |
◆ setValues() [1/3]
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/3]
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() [3/3]
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
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 |
length_error | if the Matrix isn't square |
- Returns
- \(|A|\)
◆ 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
- \( I \)
◆ mminor
double mminor |
( |
const Matrix & |
A, |
|
|
int |
i, |
|
|
int |
j |
|
) |
| |
|
friend |
Calculate a particular minor for a square matrix (i.e., the determinant 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
-
out_of_range | if i or j are out of bounds |
- Returns
- The minor
◆ multiply
Matrix multiply |
( |
const Vector & |
a, |
|
|
const Vector & |
b |
|
) |
| |
|
friend |
Multiply a column Vector and a row Vector.
Note: We can't overload the * operator for this purpose because it is already overloaded in the Vector class for the dot/inner product
- Parameters
-
a | The column Vector |
b | The row Vector |
- 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 different elements (beyond a given TOLERANCE).
- 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* [1/5]
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} \) (m x s)
◆ operator* [2/5]
Vector operator* |
( |
const Vector & |
v, |
|
|
const Matrix & |
M |
|
) |
| |
|
friend |
Multiply a row Vector and a Matrix.
Note: This method must return by value because the result Vector is a local variable.
It is worth noting that, if this method returned a Matrix rather than a Vector, it could be implemented as return (Matrix(v) * M);
- Parameters
-
- Exceptions
-
length_error | if the shapes of v and M do not conform |
- Returns
- The row Vector \( \mathbf{v} \mathbf{M} \)
◆ operator* [3/5]
Vector operator* |
( |
const Matrix & |
M, |
|
|
const Vector & |
v |
|
) |
| |
|
friend |
Multiply a Matrix and a column Vector.
Note: This method must return by value because the result Matrix is a local variable.
It is worth noting that, if this method returned a Matrix rather than a Vector, it could be implemented as return return (M * Matrix(v));
- Parameters
-
M | The Matrix |
v | The column Vector |
- Returns
- column Vector \( \mathbf{M} \mathbf{v} \)
◆ operator* [4/5]
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* [5/5]
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 the Matrix B from the Matrix A (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 (within a given TOLERANCE for each element).
- 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
◆ submatrix
Remove a row and column from a matrix
- Parameters
-
A | The matrix (which must be square) |
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 columns in this Matrix.
◆ rows
The number of rows in this Matrix.
◆ values
The documentation for this class was generated from the following files: