maliput
Matrix< N > Class Template Reference

## Detailed Description

### template<std::size_t N> class maliput::math::Matrix< N >

A squared N-dimensional matrix.

Template Parameters
 N Indicates the dimension of the matrix. Dimension must be 1x1 or greater.

#include <include/maliput/math/matrix.h>

## Public Member Functions

Matrix ()=default
Constructs a N x N matrix filled with zeros. More...

Matrix (const std::initializer_list< double > &values)
Constructs a N x N matrix from a list of double. More...

Matrix (const std::initializer_list< Vector< N >> &rows)
Constructs a N x N matrix from a list of Vector<N>. More...

Matrix (std::array< Vector< N >, N > rows)
Constructs a N x N matrix from an array of Vector<N>. More...

Matrix (const Matrix< N > &other)=default
Copy constructor. More...

Matrix (Matrix< N > &&other)=default
Move constructor. More...

const Vector< N > row (std::size_t index) const
Returns the index-th row of the matrix. More...

const Vector< N > col (std::size_t index) const
Returns the index-th column of the matrix. More...

Matrix< N > transpose () const

Matrix< N - 1 > reduce (std::size_t row, std::size_t col) const
Reduce the matrix's dimension. More...

double cofactor (std::size_t row, std::size_t col) const
Calculates the cofactor of the element at row and col. More...

double determinant () const
Computes the determinant. More...

bool is_singular () const
Determine the singularity. More...

Matrix< N > cofactor () const

Matrix< N > adjoint () const

Matrix< N > inverse () const

std::string to_str () const

Matrix< N > & operator= (const Matrix< N > &other)

Matrix< N > & operator= (const Matrix< N > &&other)

const Vector< N > & operator[] (std::size_t index) const
Constant subscripting array operator overload. More...

Vector< N > & operator[] (std::size_t index)

bool operator== (const Matrix< N > &matrix) const

bool operator!= (const Matrix< N > &matrix) const

Matrix< N > operator+ (const Matrix< N > &matrix) const

Matrix< N > operator- (const Matrix< N > &matrix) const

Matrix< N > operator* (const Matrix< N > &matrix) const
Product operator overload between Matrix<N>s. More...

Matrix< N > operator/ (double k) const
Divide operator overload between this and a scalar. More...

double cofactor (std::size_t row, std::size_t col) const

## Static Public Member Functions

static Matrix< N > Identity ()

## Static Public Attributes

static constexpr double kTolerance = 1e-15
Tolerance value to determine the singularity of the matrix. More...

## Friends

template<std::size_t N_>
Matrix< N_ > operator* (const Matrix< N_ > &matrix, double k)
Product operator overload between a Matrix<N> and a scalar. More...

template<std::size_t N_>
Matrix< N_ > operator* (double k, const Matrix< N_ > &matrix)
Product operator overload between a scalar and a Matrix<N>. More...

template<std::size_t N_>
std::ostream & operator<< (std::ostream &os, const Matrix< N_ > &matrix)

## ◆ Matrix() [1/6]

 Matrix ( )
default

Constructs a N x N matrix filled with zeros.

## ◆ Matrix() [2/6]

 Matrix ( const std::initializer_list< double > & values )

Constructs a N x N matrix from a list of double.

Parameters
 values Elements of the matrix. The size of values must match NxN. Elements will fill the matrix's rows from top to bottom.
Exceptions
 common::assertion_error When N is not positive. common::assertion_error When values size is not NxN.

## ◆ Matrix() [3/6]

 Matrix ( const std::initializer_list< Vector< N >> & rows )

Constructs a N x N matrix from a list of Vector<N>.

Parameters
 rows Rows of the matrix. The size of rows must be N. It fills the matrix from the 0-th to N-1-th.
Exceptions
 common::assertion_error When rows size is not N.

## ◆ Matrix() [4/6]

 Matrix ( std::array< Vector< N >, N > rows )

Constructs a N x N matrix from an array of Vector<N>.

Parameters
 rows Rows of the matrix. The size of rows must match with N. It fills the matrix from top to bottom.

## ◆ Matrix() [5/6]

 Matrix ( const Matrix< N > & other )
default

Copy constructor.

## ◆ Matrix() [6/6]

 Matrix ( Matrix< N > && other )
default

Move constructor.

## Member Function Documentation

Returns
Exceptions
 common::assertion_error When N is one.

## ◆ cofactor() [1/3]

 Matrix< N > cofactor
Returns
The cofactor matrix.
Exceptions
 common::assertion_error When N is one.

## ◆ cofactor() [2/3]

 double cofactor ( std::size_t row, std::size_t col ) const

Calculates the cofactor of the element at row and col.

Parameters
 row Index of the matrix's rows. It must be in [0, N). col Index of the matrix's cols. It must be in [0, N).
Returns
The cofactor value.
Exceptions
 common::assertion_error When row or col are not in [0, N). common::assertion_error When N is one.

## ◆ cofactor() [3/3]

 double cofactor ( std::size_t row, std::size_t col ) const

## ◆ col()

 const Vector< N > col ( std::size_t index ) const

Returns the index-th column of the matrix.

Parameters
 index Column number. It must be in [0, N).
Returns
A Vector<N>.
Exceptions
 common::assertion_error When index is not in the range [0, N).

## ◆ determinant()

 double determinant

Computes the determinant.

Returns
The determinant value.

## ◆ Identity()

 Matrix< N > Identity
static
Returns
A N x N identity matrix.

## ◆ inverse()

 Matrix< N > inverse
Returns
The inverse matrix.
Exceptions
 common::assertion_error When matrix is singular.

## ◆ is_singular()

 bool is_singular

Determine the singularity.

Returns
True when this matrix is singular.

## ◆ operator!=()

 bool operator!= ( const Matrix< N > & matrix ) const

## ◆ operator*()

 Matrix< N > operator* ( const Matrix< N > & matrix ) const

## ◆ operator+()

 Matrix< N > operator+ ( const Matrix< N > & matrix ) const

## ◆ operator-()

 Matrix< N > operator- ( const Matrix< N > & matrix ) const

## ◆ operator/()

 Matrix< N > operator/ ( double k ) const

Divide operator overload between this and a scalar.

## ◆ operator=() [1/2]

 Matrix< N > & operator= ( const Matrix< N > && other )

Parameters
 other Matrix object.

## ◆ operator=() [2/2]

 Matrix< N > & operator= ( const Matrix< N > & other )

Parameters
 other Matrix object.

## ◆ operator==()

 bool operator== ( const Matrix< N > & matrix ) const

## ◆ operator[]() [1/2]

 Vector< N > & operator[] ( std::size_t index )

Parameters
 index The index of the matrix row. It must be in [0, N).
Returns
A mutable reference to the row at index.
Exceptions
 common::assertion_error When index is out of range.

## ◆ operator[]() [2/2]

 const Vector< N > & operator[] ( std::size_t index ) const

Parameters
 index The index of the matrix row. It must be in [0, N).
Returns
A constant reference of the row at index.
Exceptions
 common::assertion_error When index is out of range.

## ◆ reduce()

 Matrix< N - 1 > reduce ( std::size_t row, std::size_t col ) const

Reduce the matrix's dimension.

N must be at least 2 to be reducible.

Parameters
 row Is the number of the row to be removed. It must be in [0, N). col Is the number of the column to be removed. It must be in [0, N).
Returns
A Matrix<N-1> which is the result of removing the row-th row and col-th column.
Exceptions
 common::assertion_error When row or col are not in [0, N). common::assertion_error When N is less than two.

## ◆ row()

 const Vector< N > row ( std::size_t index ) const

Returns the index-th row of the matrix.

Parameters
 index Row number. It must be in [0, N).
Returns
A Vector<N>.
Exceptions
 common::assertion_error When index is not in the range [0, N).

## ◆ to_str()

 std::string to_str
Returns
A string representation of the matrix.

## ◆ transpose()

 Matrix< N > transpose
Returns
A Matrix<N> whose elements match this transpose.

## ◆ operator* [1/2]

 Matrix operator* ( const Matrix< N_ > & matrix, double k )
friend

Product operator overload between a Matrix<N> and a scalar.

## ◆ operator* [2/2]

 Matrix operator* ( double k, const Matrix< N_ > & matrix )
friend

Product operator overload between a scalar and a Matrix<N>.

## ◆ operator<<

 std::ostream& operator<< ( std::ostream & os, const Matrix< N_ > & matrix )
friend