regina::NMatrix2 Class Reference
Mathematical Support

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...

## 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

  cloneMe | the 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

  values | the 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

  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.

## 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

  compare | the 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

  other | the 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

  scalar | the integer that this matrix should be multiplied by.

Returns
  the product this * scalar.

NMatrix2& regina::NMatrix2::operator*= | ( | const NMatrix2 & | other | ) |

Multiplies this by the given matrix.

This matrix is changed to reflect the result.

Parameters

  other | the matrix by which this should be multiplied.

Returns
  a reference to this matrix with its new value.

NMatrix2 & regina::NMatrix2::operator*= | ( | long | scalar | ) |

inline

Multiplies this by the given scalar.

This matrix is changed to reflect the result.

Parameters

  scalar | the scalar 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

  other | the 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

  other | the matrix to add to this.

Returns
  a reference to this matrix with its new value.

NMatrix2 regina::NMatrix2::operator- | ( | const NMatrix2 & | other | ) | const

inline

Calculates the difference of two matrices.

Neither this nor the given matrix is changed.

Parameters

  other | the matrix to subtract from this.

Returns
  the difference this - other.

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 | ) |

inline

Subtracts the given matrix from this.

This matrix is changed to reflect the result.

Parameters

  other | the 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

  cloneMe | the 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

  values | the 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

  compare | the matrix with which this will be compared.

Returns
  `true` if and only if this matrix is equal to compare.

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

  row | the index of the requested row; this must be 0 or 1.

Returns
  a two-integer array containing the elements of the requested row.

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

  row | the 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

  out | the output stream to which to write.
  mat | the matrix to write.

Returns
  a reference to out.

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

- maths/nmatrix2.h

Copyright © 1999-2014, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).