Regina Calculation Engine
|
Represents a 2-by-2 integer matrix. More...
#include <maths/nmatrix2.h>
Public Member Functions | |
NMatrix2 () | |
Initialises to the zero matrix. More... | |
NMatrix2 (const NMatrix2 &cloneMe) | |
Initialises to a copy of the given matrix. More... | |
NMatrix2 (const long values[2][2]) | |
Initialises to the given integer values. More... | |
NMatrix2 (long val00, long val01, long val10, long val11) | |
Initialises to the given integer values. More... | |
NMatrix2 & | operator= (const NMatrix2 &cloneMe) |
Sets this matrix to be a copy of the given matrix. More... | |
NMatrix2 & | operator= (const long values[2][2]) |
Sets the elements of this matrix to the given integer values. More... | |
const long * | operator[] (unsigned row) const |
Returns a single row of this matrix. More... | |
long * | operator[] (unsigned row) |
Returns a single row of this matrix. More... | |
NMatrix2 | operator* (const NMatrix2 &other) const |
Calculates the matrix product of this and the given matrix. More... | |
NMatrix2 | operator* (long scalar) const |
Calculates the scalar product of this matrix and the given integer. More... | |
NMatrix2 | operator+ (const NMatrix2 &other) const |
Calculates the sum of two matrices. More... | |
NMatrix2 | operator- (const NMatrix2 &other) const |
Calculates the difference of two matrices. More... | |
NMatrix2 | operator- () const |
Determines the negative of this matrix. More... | |
NMatrix2 | transpose () const |
Returns the transpose of this matrix. More... | |
NMatrix2 | inverse () const |
Calculates the inverse of this matrix. More... | |
NMatrix2 & | operator+= (const NMatrix2 &other) |
Adds the given matrix to this. More... | |
NMatrix2 & | operator-= (const NMatrix2 &other) |
Subtracts the given matrix from this. More... | |
NMatrix2 & | operator*= (const NMatrix2 &other) |
Multiplies this by the given matrix. More... | |
NMatrix2 & | operator*= (long scalar) |
Multiplies this by the given scalar. More... | |
void | negate () |
Negates this matrix. More... | |
bool | invert () |
Inverts this matrix. More... | |
bool | operator== (const NMatrix2 &compare) const |
Determines if this is equal to the given matrix. More... | |
bool | operator!= (const NMatrix2 &compare) const |
Determines if this is not equal to the given matrix. More... | |
long | determinant () const |
Returns the determinant of this matrix. More... | |
bool | isIdentity () const |
Determines if this is the 2x2 identity matrix. More... | |
bool | isZero () const |
Determines if this is the 2x2 zero matrix. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const NMatrix2 &mat) |
Writes the given matrix to the given output stream. More... | |
Represents a 2-by-2 integer matrix.
The advantages of using this class over the larger NMatrixInt and friends is that this class has less overhead and offers additional mathematical support routines that the larger classes do not.
This class only contains four long integers, and so it may be considered small enough to pass about by value.
|
inline |
Initialises to the zero matrix.
|
inline |
Initialises to a copy of the given matrix.
cloneMe | the matrix to be copied. |
|
inline |
Initialises to the given integer values.
Each given integer values[r][c]
will be placed in row r, column c.
values | the four values to insert into the new matrix. |
|
inline |
Initialises to the given integer values.
val00 | the value to place in row 0, column 0. |
val01 | the value to place in row 0, column 1. |
val10 | the value to place in row 1, column 0. |
val11 | the value to place in row 1, column 1. |
|
inline |
Returns the determinant of this matrix.
NMatrix2 regina::NMatrix2::inverse | ( | ) | const |
Calculates the inverse of this matrix.
This matrix is not changed.
This routine only works for integer matrices whose determinant is either +1 or -1.
bool regina::NMatrix2::invert | ( | ) |
Inverts this matrix.
This routine only works for integer matrices whose determinant is either +1 or -1. Otherwise this matrix is left unchanged.
true
if this matrix was successfully inverted (i.e., its determinant was +1 or -1), or false
otherwise.
|
inline |
Determines if this is the 2x2 identity matrix.
true
if this is the identity matrix, or false
otherwise.
|
inline |
Determines if this is the 2x2 zero matrix.
true
if this is the zero matrix, or false
otherwise.
|
inline |
Negates this matrix.
This matrix is changed to reflect the result.
|
inline |
Determines if this is not equal to the given matrix.
compare | the matrix with which this will be compared. |
true
if and only if this matrix is not equal to compare. Calculates the matrix product of this and the given matrix.
Neither this nor the given matrix is changed.
other | the matrix that this should be multiplied by. |
|
inline |
Calculates the scalar product of this matrix and the given integer.
This matrix is not changed.
scalar | the integer that this matrix should be multiplied by. |
Multiplies this by the given matrix.
This matrix is changed to reflect the result.
other | the matrix by which this should be multiplied. |
|
inline |
Multiplies this by the given scalar.
This matrix is changed to reflect the result.
scalar | the scalar by which this should be multiplied. |
Calculates the sum of two matrices.
Neither this nor the given matrix is changed.
other | the matrix to add to this. |
Adds the given matrix to this.
This matrix is changed to reflect the result.
other | the matrix to add to this. |
Calculates the difference of two matrices.
Neither this nor the given matrix is changed.
other | the matrix to subtract from this. |
|
inline |
Determines the negative of this matrix.
This matrix is not changed.
Subtracts the given matrix from this.
This matrix is changed to reflect the result.
other | the matrix to subtract from this. |
Sets this matrix to be a copy of the given matrix.
cloneMe | the matrix to be copied. |
|
inline |
Sets the elements of this matrix to the given integer values.
Each given integer values[r][c]
will be placed in row r, column c.
values | the four values to copy into this matrix. |
|
inline |
Determines if this is equal to the given matrix.
compare | the matrix with which this will be compared. |
true
if and only if this matrix is equal to compare.
|
inline |
Returns a single row of this matrix.
This means that the integer in row r, column c can be accessed as myMatrix[r][c]
(where r and c are each 0 or 1).
row | the index of the requested row; this must be 0 or 1. |
|
inline |
Returns a single row of this matrix.
This means that the integer in row r, column c can be accessed as myMatrix[r][c]
(where r and c are each 0 or 1). Each such element may be modified directly.
row | the index of the requested row; this must be 0 or 1. |
|
inline |
Returns the transpose of this matrix.
This matrix is not changed.
|
friend |
Writes the given matrix to the given output stream.
The matrix will be written entirely on a single line, with the first row followed by the second row.
out | the output stream to which to write. |
mat | the matrix to write. |