Core 1.0
MatrixMN Class Reference

A simple, non-optimized implementation of rectangular matrixes. More...

#include <matrix-mn.h>

Public Member Functions

 MatrixMN (int, int, double=0.0)
 Create a rectangular matrix.
 MatrixMN (int, double=0.0)
 Create a square matrix.
 MatrixMN (int, int, const std::vector< double > &)
 Create a square matrix.
 MatrixMN (const std::vector< std::vector< double > > &)
 Creates a rectangular matrix from a 2D std::vector.
double & operator() (int, int)
 Return the matrix term value for given indexess.
double operator() (int, int) const
 Return the matrix term value for given indexess.
void SwapRows (int, int)
 Swap rows.
MatrixMN Transpose () const
 Transpose.
MatrixMN Inverse () const
 Compute the Gauss Jordan inverse.
MatrixMNoperator+= (const MatrixMN &)
 Self sum.
MatrixMNoperator-= (const MatrixMN &)
 Self difference.
MatrixMNoperator*= (const MatrixMN &)
 Self product.
MatrixMNoperator*= (const double &)
 Self multiply by a scalar.
MatrixMNoperator/= (const double &)
 Self division by a scalar.

Static Public Member Functions

static MatrixMN Identity (int)
 Create the identity matrix.
static MatrixMN Covariance (const std::vector< std::vector< double > > &vectors)
 Create the covariance matrix of a given set of vectors.

Protected Member Functions

int Index (int, int) const
 Compute the entry of a term.
bool SameSize (const MatrixMN &) const
 Test if the matrix has the same size as the argument matrix.

Protected Attributes

int m = 0
 Rows.
int n = 0
 Columns.
std::vector< double > v
 Array of data.

Friends

MatrixMN operator+ (const MatrixMN &a, const MatrixMN &b)
 Sum.
MatrixMN operator- (const MatrixMN &a, const MatrixMN &b)
 Difference.
MatrixMN operator* (const MatrixMN &a, const MatrixMN &b)
 Product.
MatrixMN operator* (const MatrixMN &a, double b)
 Right multiply by a scalar.
MatrixMN operator* (double b, MatrixMN &a)
 Left multiply by a scalar.
std::ostream & operator<< (std::ostream &s, const MatrixMN &mat)
 Overloaded.

Detailed Description

A simple, non-optimized implementation of rectangular matrixes.

Author
Hugo Schott

Constructor & Destructor Documentation

◆ MatrixMN() [1/4]

MatrixMN::MatrixMN ( int m,
int n,
double d = 0.0 )

Create a rectangular matrix.

Parameters
m,nSize in rows, columns.
dDefault scalar value.

◆ MatrixMN() [2/4]

MatrixMN::MatrixMN ( int n,
double d = 0.0 )

Create a square matrix.

Parameters
nSize.
dDefault scalar value.

◆ MatrixMN() [3/4]

MatrixMN::MatrixMN ( int m,
int n,
const std::vector< double > & data )

Create a square matrix.

Parameters
m,nSize in rows, columns.
dataLinearized array of values.

◆ MatrixMN() [4/4]

MatrixMN::MatrixMN ( const std::vector< std::vector< double > > & data)

Creates a rectangular matrix from a 2D std::vector.

Parameters
data2D std::vector, each row must have same number of elements.

Member Function Documentation

◆ Covariance()

MatrixMN MatrixMN::Covariance ( const std::vector< std::vector< double > > & vectors)
static

Create the covariance matrix of a given set of vectors.

Parameters
vectorsSet of vectors, they must have the same size.

◆ Identity()

MatrixMN MatrixMN::Identity ( int n)
static

Create the identity matrix.

Parameters
nSize.

◆ Index()

int MatrixMN::Index ( int i,
int j ) const
inlineprotected

Compute the entry of a term.

Parameters
i,jIndexes.

◆ Inverse()

MatrixMN MatrixMN::Inverse ( ) const

Compute the Gauss Jordan inverse.

The function only works the matrix is squared

◆ operator()() [1/2]

double & MatrixMN::operator() ( int i,
int j )
inline

Return the matrix term value for given indexess.

Parameters
i,jInteger coordinates of the vertex.

◆ operator()() [2/2]

double MatrixMN::operator() ( int i,
int j ) const
inline

Return the matrix term value for given indexess.

Parameters
i,jInteger coordinates of the vertex.

◆ operator*=() [1/2]

MatrixMN & MatrixMN::operator*= ( const double & d)

Self multiply by a scalar.

Parameters
dReal.

◆ operator*=() [2/2]

MatrixMN & MatrixMN::operator*= ( const MatrixMN & a)

Self product.

Parameters
aMatrix.

◆ operator+=()

MatrixMN & MatrixMN::operator+= ( const MatrixMN & a)

Self sum.

Parameters
aMatrix.

◆ operator-=()

MatrixMN & MatrixMN::operator-= ( const MatrixMN & a)

Self difference.

Parameters
aMatrix.

◆ operator/=()

MatrixMN & MatrixMN::operator/= ( const double & d)

Self division by a scalar.

Parameters
dReal.

◆ SameSize()

bool MatrixMN::SameSize ( const MatrixMN & A) const
inlineprotected

Test if the matrix has the same size as the argument matrix.

Parameters
AMatrix

◆ SwapRows()

void MatrixMN::SwapRows ( int i,
int j )

Swap rows.

Parameters
i,jIndexes.

◆ operator* [1/3]

MatrixMN operator* ( const MatrixMN & a,
const MatrixMN & b )
friend

Product.

Parameters
a,bMatrixes.

◆ operator* [2/3]

MatrixMN operator* ( const MatrixMN & a,
double b )
friend

Right multiply by a scalar.

Parameters
aMatrix.
bReal.

◆ operator* [3/3]

MatrixMN operator* ( double b,
MatrixMN & a )
friend

Left multiply by a scalar.

Parameters
aMatrix.
bReal.

◆ operator+

MatrixMN operator+ ( const MatrixMN & a,
const MatrixMN & b )
friend

Sum.

Parameters
a,bMatrixes.

◆ operator-

MatrixMN operator- ( const MatrixMN & a,
const MatrixMN & b )
friend

Difference.

Parameters
a,bMatrixes.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const MatrixMN & mat )
friend

Overloaded.

Parameters
sStream.
matMatrix.