Regina Calculation Engine
Public Member Functions | Friends
regina::NMatrix2 Class Reference

Represents a 2-by-2 integer matrix. More...

#include <maths/nmatrix2.h>

List of all members.

Public Member Functions

 NMatrix2 ()
 Initialises to the zero matrix.
 NMatrix2 (const NMatrix2 &cloneMe)
 Initialises to a copy of the given matrix.
 NMatrix2 (const long values[2][2])
 Initialises to the given integer values.
 NMatrix2 (long val00, long val01, long val10, long val11)
 Initialises to the given integer values.
NMatrix2operator= (const NMatrix2 &cloneMe)
 Sets this matrix to be a copy of the given matrix.
NMatrix2operator= (const long values[2][2])
 Sets the elements of this matrix to the given integer values.
const long * operator[] (unsigned row) const
 Returns a single row of this matrix.
long * operator[] (unsigned row)
 Returns a single row of this matrix.
NMatrix2 operator* (const NMatrix2 &other) const
 Calculates the matrix product of this and the given matrix.
NMatrix2 operator* (long scalar) const
 Calculates the scalar product of this matrix and the given integer.
NMatrix2 operator+ (const NMatrix2 &other) const
 Calculates the sum of two matrices.
NMatrix2 operator- (const NMatrix2 &other) const
 Calculates the difference of two matrices.
NMatrix2 operator- () const
 Determines the negative of this matrix.
NMatrix2 transpose () const
 Returns the transpose of this matrix.
NMatrix2 inverse () const
 Calculates the inverse of this matrix.
NMatrix2operator+= (const NMatrix2 &other)
 Adds the given matrix to this.
NMatrix2operator-= (const NMatrix2 &other)
 Subtracts the given matrix from this.
NMatrix2operator*= (const NMatrix2 &other)
 Multiplies this by the given matrix.
NMatrix2operator*= (long scalar)
 Multiplies this by the given scalar.
void negate ()
 Negates this matrix.
bool invert ()
 Inverts this matrix.
bool operator== (const NMatrix2 &compare) const
 Determines if this is equal to the given matrix.
bool operator!= (const NMatrix2 &compare) const
 Determines if this is not equal to the given matrix.
long determinant () const
 Returns the determinant of this matrix.
bool isIdentity () const
 Determines if this is the 2x2 identity matrix.
bool isZero () const
 Determines if this is the 2x2 zero matrix.

Friends

std::ostream & operator<< (std::ostream &out, const NMatrix2 &mat)
 Writes the given matrix to the given output stream.

Detailed Description

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.


Constructor & Destructor Documentation

regina::NMatrix2::NMatrix2 ( ) [inline]

Initialises to the zero matrix.

regina::NMatrix2::NMatrix2 ( const NMatrix2 cloneMe) [inline]

Initialises to a copy of the given matrix.

Parameters:
cloneMethe matrix to be copied.
regina::NMatrix2::NMatrix2 ( const long  values[2][2]) [inline]

Initialises to the given integer values.

Each given integer values[r][c] will be placed in row r, column c.

Python:
Not present.
Parameters:
valuesthe four values to insert into the new matrix.
regina::NMatrix2::NMatrix2 ( long  val00,
long  val01,
long  val10,
long  val11 
) [inline]

Initialises to the given integer values.

Parameters:
val00the value to place in row 0, column 0.
val01the value to place in row 0, column 1.
val10the value to place in row 1, column 0.
val11the value to place in row 1, column 1.

Member Function Documentation

long regina::NMatrix2::determinant ( ) const [inline]

Returns the determinant of this matrix.

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.

Returns:
the inverse of this matrix. If this matrix does not have determinant +1 or -1, the zero matrix will be returned instead.
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.

Returns:
true if this matrix was successfully inverted (i.e., its determinant was +1 or -1), or false otherwise.
bool regina::NMatrix2::isIdentity ( ) const [inline]

Determines if this is the 2x2 identity matrix.

Returns:
true if this is the identity matrix, or false otherwise.
bool regina::NMatrix2::isZero ( ) const [inline]

Determines if this is the 2x2 zero matrix.

Returns:
true if this is the zero matrix, or false otherwise.
void regina::NMatrix2::negate ( ) [inline]

Negates this matrix.

This matrix is changed to reflect the result.

bool regina::NMatrix2::operator!= ( const NMatrix2 compare) const [inline]

Determines if this is not equal to the given matrix.

Parameters:
comparethe matrix with which this will be compared.
Returns:
true if and only if this matrix is not equal to compare.
NMatrix2 regina::NMatrix2::operator* ( const NMatrix2 other) const [inline]

Calculates the matrix product of this and the given matrix.

Neither this nor the given matrix is changed.

Parameters:
otherthe matrix that this should be multiplied by.
Returns:
the product this * other.
NMatrix2 regina::NMatrix2::operator* ( long  scalar) const [inline]

Calculates the scalar product of this matrix and the given integer.

This matrix is not changed.

Parameters:
scalarthe integer that this matrix should be multiplied by.
Returns:
the product this * scalar.
NMatrix2 & regina::NMatrix2::operator*= ( long  scalar) [inline]

Multiplies this by the given scalar.

This matrix is changed to reflect the result.

Parameters:
scalarthe scalar by which this should be multiplied.
Returns:
a reference to this matrix with its new value.
NMatrix2& regina::NMatrix2::operator*= ( const NMatrix2 other)

Multiplies this by the given matrix.

This matrix is changed to reflect the result.

Parameters:
otherthe matrix by which this should be multiplied.
Returns:
a reference to this matrix with its new value.
NMatrix2 regina::NMatrix2::operator+ ( const NMatrix2 other) const [inline]

Calculates the sum of two matrices.

Neither this nor the given matrix is changed.

Parameters:
otherthe matrix to add to this.
Returns:
the sum this + other.
NMatrix2 & regina::NMatrix2::operator+= ( const NMatrix2 other) [inline]

Adds the given matrix to this.

This matrix is changed to reflect the result.

Parameters:
otherthe matrix to add to this.
Returns:
a reference to this matrix with its new value.
NMatrix2 regina::NMatrix2::operator- ( ) const [inline]

Determines the negative of this matrix.

This matrix is not changed.

Returns:
the negative of this matrix.
NMatrix2 regina::NMatrix2::operator- ( const NMatrix2 other) const [inline]

Calculates the difference of two matrices.

Neither this nor the given matrix is changed.

Parameters:
otherthe matrix to subtract from this.
Returns:
the difference this - other.
NMatrix2 & regina::NMatrix2::operator-= ( const NMatrix2 other) [inline]

Subtracts the given matrix from this.

This matrix is changed to reflect the result.

Parameters:
otherthe matrix to subtract from this.
Returns:
a reference to this matrix with its new value.
NMatrix2 & regina::NMatrix2::operator= ( const NMatrix2 cloneMe) [inline]

Sets this matrix to be a copy of the given matrix.

Parameters:
cloneMethe matrix to be copied.
Returns:
a reference to this matrix.
NMatrix2 & regina::NMatrix2::operator= ( const long  values[2][2]) [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.

Python:
Not present.
Parameters:
valuesthe four values to copy into this matrix.
Returns:
a reference to this matrix.
bool regina::NMatrix2::operator== ( const NMatrix2 compare) const [inline]

Determines if this is equal to the given matrix.

Parameters:
comparethe matrix with which this will be compared.
Returns:
true if and only if this matrix is equal to compare.
long * regina::NMatrix2::operator[] ( unsigned  row) [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.

Parameters:
rowthe index of the requested row; this must be 0 or 1.
Returns:
a two-integer array containing the elements of the requested row.
const long * regina::NMatrix2::operator[] ( unsigned  row) const [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).

Parameters:
rowthe index of the requested row; this must be 0 or 1.
Returns:
a two-integer array containing the elements of the requested row.
NMatrix2 regina::NMatrix2::transpose ( ) const [inline]

Returns the transpose of this matrix.

This matrix is not changed.

Returns:
the transpose of this matrix.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const NMatrix2 mat 
) [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.

Parameters:
outthe output stream to which to write.
matthe matrix to write.
Returns:
a reference to out.

The documentation for this class was generated from the following file:

Copyright © 1999-2011, The Regina development team
This software is released under the GNU General Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).