DUNE: Uniform Navigational Environment  2016.09.0
DUNE::Math::Matrix Class Reference

Classes

class  Error
 

Public Member Functions

 Matrix (void)
 
 Matrix (const Matrix &m)
 
 Matrix (double *data, size_t r, size_t c)
 
 Matrix (size_t r, size_t c)
 
 Matrix (size_t r, size_t c, double v)
 
 Matrix (size_t n)
 
 Matrix (double *diag, size_t n)
 
 ~Matrix (void)
 
int rows (void) const
 
int columns (void) const
 
int size (void) const
 
bool isEmpty (void) const
 
void fill (double value)
 
void fill (size_t r, size_t c, const double *data=0)
 
void identity (void)
 
void maxLimitValues (double max)
 
void minLimitValues (double min)
 
void trimValues (double min, double max)
 
void trimValues (double lim)
 
Matrix get (size_t i1, size_t i2, size_t j1, size_t j2) const
 
Matrixset (size_t i1, size_t i2, size_t j1, size_t j2, const Matrix &m_in)
 
MatrixblkDiag (const Matrix &m_in)
 
MatrixvertCat (const Matrix &m_in)
 
MatrixhorzCat (const Matrix &m_in)
 
Matrixpow (unsigned int n)
 
void toFile (const char *path)
 
void fromFile (const char *path)
 
void readFromLines (const std::vector< std::string > &clines)
 
void readFromConfig (DUNE::Parsers::Config &cfg, const std::string &section, const std::string &param)
 
Matrix row (size_t i) const
 
Matrix column (size_t j) const
 
void swapColumns (size_t i, size_t j)
 
void swapRows (size_t i, size_t j)
 
void resize (const Matrix &m)
 
void resize (size_t r, size_t c)
 
void resizeAndKeep (size_t r, size_t c)
 
void resizeAndFill (size_t r, size_t c, double value)
 
double & operator() (size_t i, size_t j)
 
double operator() (size_t i, size_t j) const
 
double & operator() (size_t i)
 
double operator() (size_t i) const
 
double element (size_t i, size_t j) const
 
double element (size_t i)
 
void to_row (void)
 
void to_column (void)
 
Matrix multiply (const Matrix &m)
 
bool operator== (const Matrix &m) const
 
Matrixoperator= (const Matrix &m)
 
Matrixoperator+= (const Matrix &m)
 
Matrixoperator-= (const Matrix &m)
 
Matrixoperator&= (const Matrix &m)
 
Matrixoperator/= (const Matrix &m)
 
Matrix operator- (void)
 
Matrixoperator*= (double x)
 
Matrixoperator/= (double x)
 
void put (size_t i, size_t j, const Matrix &a)
 
Matrix mminor (size_t i, size_t j) const
 
unsigned int lup (Matrix &L, Matrix &U, Matrix &P) const
 
void lu (Matrix &L, Matrix &U) const
 
double detr (void) const
 
double det (void) const
 
bool Sylvester (void) const
 
Matrix toDCM (void) const
 
Matrix toQuaternion (void) const
 
Matrix toEulerAngles (void) const
 
Matrix expmts (double tol=1e-05) const
 
double norm_p (double p) const
 
double norm_2 (void) const
 
double norm_inf (void) const
 
double median (void) const
 
double trace (void) const
 
bool isInvertible (void) const
 
bool isSquare (void) const
 
bool isVector (void) const
 
bool isColumnVector (void) const
 
bool isColumnVector (size_t rows) const
 
bool isRowVector (void) const
 
bool isRowVector (size_t columns) const
 

Static Public Member Functions

static void set_precision (double p)
 
static double get_precision (void)
 
static double dot (const Matrix &a, const Matrix &b)
 
static Matrix cross (const Matrix &a, const Matrix &b)
 
static int upper_triangular_pp (double *M, int n, int m, double tolerance)
 
static int upper_triangular_tp (double *M, int *index, int n, int m, double tolerance)
 

Friends

DUNE_DLL_SYM Matrix operator+ (const Matrix &m1, const Matrix &m2)
 
DUNE_DLL_SYM Matrix operator- (const Matrix &m1, const Matrix &m2)
 
DUNE_DLL_SYM Matrix operator* (const Matrix &m1, const Matrix &m2)
 
DUNE_DLL_SYM Matrix operator& (const Matrix &m1, const Matrix &m2)
 
DUNE_DLL_SYM Matrix operator/ (const Matrix &a, const Matrix &b)
 
DUNE_DLL_SYM Matrix operator* (double x, const Matrix &a)
 
DUNE_DLL_SYM Matrix operator* (const Matrix &a, double x)
 
DUNE_DLL_SYM Matrix operator/ (const Matrix &a, double x)
 
DUNE_DLL_SYM std::ostream & operator<< (std::ostream &os, const Matrix &a)
 
DUNE_DLL_SYM std::istream & operator>> (std::istream &is, Matrix &a)
 
DUNE_DLL_SYM Matrix transpose (const Matrix &a)
 
DUNE_DLL_SYM Matrix inverse (const Matrix &a)
 
DUNE_DLL_SYM Matrix inverse (const Matrix &a, const Matrix &b)
 
Matrix skew (double data[3])
 
Matrix skew (const Matrix &a)
 
Matrix inverse_pp (const Matrix &a)
 
Matrix inverse_pp (const Matrix &, const Matrix &)
 
Matrix inverse_lup (const Matrix &a)
 
Matrix abs (const Matrix &a)
 
double max (const Matrix &a)
 
double min (const Matrix &a)
 
double sum (const Matrix &a)
 
double squaresum (const Matrix &a)
 

Constructor & Destructor Documentation

DUNE::Math::Matrix::Matrix ( void  )

Constructor.

Construct a zero sized matrix.

Referenced by DUNE::Math::operator>>(), toDCM(), toEulerAngles(), and toQuaternion().

DUNE::Math::Matrix::Matrix ( const Matrix m)

Constructor.

Create a Matrix of the same dimension of another Matrix. It simply sets the new data pointer to the old data and increases the copy counter.

Parameters
[in]mreference to matrix
DUNE::Math::Matrix::Matrix ( double *  data,
size_t  r,
size_t  c 
)

Constructor.

Create a Matrix of dimension (rows * columns) and fills it with the data pointed by 'data'.

Parameters
[in]datapointer to data to be copied to new matrix
[in]rnumber of rows of new matrix
[in]cnumber of columns of new matrix
DUNE::Math::Matrix::Matrix ( size_t  r,
size_t  c 
)

Constructor.

Construct a matrix of size rows*columns.

Parameters
[in]rnumber of rows of new matrix
[in]cnumber of columns of new matrix
DUNE::Math::Matrix::Matrix ( size_t  r,
size_t  c,
double  v 
)

Constructor.

Construct a matrix of size rows * columns filled with constant value.

Parameters
[in]rnumber of rows of new matrix
[in]cnumber of rows of new matrix
[in]vvalue used to initialize cells.

References fill().

DUNE::Math::Matrix::Matrix ( size_t  n)

Constructor.

Construct a square identity matrix of size n param[in] n size of new matrix (n * n)

References identity().

DUNE::Math::Matrix::Matrix ( double *  diag,
size_t  n 
)

Constructor.

Construct a diagonal matrix using the values in data param[in] diag pointer to data to be copied to diagonal matrix param[in] n size of new matrix (n * n)

References fill().

DUNE::Math::Matrix::~Matrix ( void  )

Destructor.

Decrement the number of copies of a Matrix and frees the allocated memory if this number reaches zero.

Referenced by Maneuver::VehicleFormation::FormCollAvoid::Task::consume(), and Maneuver::VehicleFormation::Coordinator::Task::onUpdateParameters().

Member Function Documentation

Matrix & DUNE::Math::Matrix::blkDiag ( const Matrix m_in)

Returns the diagonal concatenation of a matrix Return a matrix of size (nrows + rows(m_in)) x (ncolumns +columns(m_in)) and fills the remaining elements with zeros.

Parameters
[in]m_inreference to matrix
Returns
reference to diagonal concatenation of matrix

References columns(), isEmpty(), resizeAndFill(), rows(), and set().

Referenced by DUNE::Control::LinearSystem::append().

Matrix DUNE::Math::Matrix::column ( size_t  j) const

This method returns a column of the Matrix.

Parameters
[in]jcolumn to be retrieved
Returns
matrix of the returned column

Referenced by Maneuver::VehicleFormation::FormCollAvoid::Task::formationControl(), and swapColumns().

Matrix DUNE::Math::Matrix::cross ( const Matrix a,
const Matrix b 
)
static

Calculate cross product.

Arguments must be 3D column or row vectors.

Parameters
[in]amatrix.
[in]bmatrix.
Returns
resultant matrix of cross product

References columns(), isEmpty(), isVector(), resizeAndFill(), rows(), and size().

double DUNE::Math::Matrix::det ( void  ) const

Matrix determinant through LUP decomposition Iterative technique O(n^3).

Returns
matrix determinant

References element(), isEmpty(), and lup().

Referenced by Sylvester().

double DUNE::Math::Matrix::detr ( void  ) const

Matrix determinant through Laplace expansion Recursive technique O(n!).

Returns
matrix determinant

References element(), isEmpty(), and mminor().

double DUNE::Math::Matrix::dot ( const Matrix a,
const Matrix b 
)
static

Calculate dot product.

Arguments must be equally sized column or row vectors.

Parameters
[in]amatrix.
[in]bmatrix.
Returns
resultant matrix of dot product

References isEmpty(), and isVector().

Referenced by DUNE::Math::QPSolver::solve().

double DUNE::Math::Matrix::element ( size_t  i,
size_t  j 
) const

This method returns the value of an entry of a Matrix.

As this is a reading method it does not care if the data is shared by other matrices.

Parameters
[in]irow index
[in]jcolumn index
Returns
value of matrix

References isEmpty().

Referenced by det(), detr(), set(), toDCM(), toEulerAngles(), and toQuaternion().

double DUNE::Math::Matrix::element ( size_t  i)

This method returns the value of an entry of a Matrix.

As this is a reading method it does not care if the data is shared by other matrices.

Parameters
[in]imatrix index
Returns
value of matrix

References isEmpty().

Matrix DUNE::Math::Matrix::expmts ( double  tol = 1e-05) const

Compute matrix exponential of a square matrix through Taylor series expansion technique.

Revised according to: "Nineteen dubious ways to compute the exponential of a matrix, twenty-five years later" SIAM Review, 2003 (pages 12-13 - "Scale and squaring method").

Parameters
[in]toltolerance value
Returns
resultant matrix

References DUNE::Math::computeNextPowerOfTwo(), expmts(), isEmpty(), and norm_p().

Referenced by DUNE::Control::LinearSystem::c2d(), and expmts().

void DUNE::Math::Matrix::fill ( size_t  r,
size_t  c,
const double *  data = 0 
)

Resize matrix and fill with new values.

Parameters
[in]rnumber of rows of resized matrix
[in]cnumber of columns of resized matrix
[in]datapointer to data to be copied to resized matrix

References resize().

void DUNE::Math::Matrix::fromFile ( const char *  path)

Loads a matrix from text file (must initialize matrix dimensions first).

Parameters
[in]pathfile path string (eg: "E:\dir/x.txt").
double DUNE::Math::Matrix::get_precision ( void  )
static

This method returns the precision currently in use.

Returns
value of the precision in use
Matrix & DUNE::Math::Matrix::horzCat ( const Matrix m_in)

Returns the horizontal concatenation of a matrix Return a matrix of size (nrows x (ncolumns + columns(m_in)) ) and fills the remaining elements with zeros.

Parameters
[in]m_inreference to matrix
Returns
reference to vertical concatenation of matrix

References columns(), isEmpty(), resizeAndFill(), rows(), and set().

Referenced by Simulators::UAV::Task::matrixJ().

void DUNE::Math::Matrix::identity ( void  )

Turns the Matrix into an identity matrix if it is squared.

References fill(), and isEmpty().

Referenced by Matrix(), and DUNE::Navigation::KalmanFilter::reset().

bool DUNE::Math::Matrix::isColumnVector ( void  ) const

This routine checks if matrix is a column vector.

Returns
true if it is a column vector, false otherwise

Referenced by DUNE::Math::QPSolver::solve().

bool DUNE::Math::Matrix::isColumnVector ( size_t  rows) const

This routine checks if matrix is a column vector with certain size.

Parameters
[in]rowssize of the vector
Returns
true if it is a column vector, false otherwise
bool DUNE::Math::Matrix::isInvertible ( void  ) const

This routine checks if matrix is invertible.

Returns
true if it is invertible, false otherwise

References isEmpty(), and upper_triangular_pp().

bool DUNE::Math::Matrix::isRowVector ( void  ) const

This routine checks if matrix is a row vector.

Returns
true if it is a row vector, false otherwise
bool DUNE::Math::Matrix::isRowVector ( size_t  columns) const

This routine checks if matrix is a row vector with certain size.

Parameters
[in]columnssize of the vector
Returns
true if it is a row vector, false otherwise
bool DUNE::Math::Matrix::isSquare ( void  ) const

This routine checks if matrix is square.

Returns
true if it is squared, false otherwise

Referenced by DUNE::Math::QPSolver::solve(), and trace().

bool DUNE::Math::Matrix::isVector ( void  ) const

This routine checks if matrix is a vector.

Returns
true if it is a vector, false otherwise

Referenced by cross(), and dot().

void DUNE::Math::Matrix::lu ( Matrix L,
Matrix U 
) const
Parameters
[in]Llower triangular matrix
[in]Uupper triangular matrix

References isEmpty().

unsigned int DUNE::Math::Matrix::lup ( Matrix L,
Matrix U,
Matrix P 
) const

LUP decomposition (P * A = L * U).

This method returns the number of permutations.

Parameters
[in]Llower triangular matrix
[in]Uupper triangular matrix
[in]Ppermutation matrix
Returns
number of permutations

References isEmpty(), multiply(), and swapRows().

Referenced by det(), and DUNE::Math::inverse_lup().

void DUNE::Math::Matrix::maxLimitValues ( double  max)

Limit the maximum Matrix elements values.

Parameters
[in]maxmaximum value

References isEmpty(), and max.

Referenced by trimValues().

double DUNE::Math::Matrix::median ( void  ) const

Compute the median value of the ordered data of the matrix.

(does not assume the data is already ordered)

Returns
median of the matrix

References isEmpty(), and DUNE::Math::median().

void DUNE::Math::Matrix::minLimitValues ( double  min)

Limit the minimum Matrix elements values.

Parameters
[in]minminimum value

References isEmpty(), and min.

Referenced by trimValues().

Matrix DUNE::Math::Matrix::mminor ( size_t  i,
size_t  j 
) const

This routine returns the (i, j) minor Matrix.

Parameters
[in]irow index
[in]jcolumn index
Returns
matrix

References isEmpty(), put(), and resizeAndFill().

Referenced by detr(), and Sylvester().

Matrix DUNE::Math::Matrix::multiply ( const Matrix m)

Right-multiply a matrix with given matrix.

Parameters
[in]mmatrix to be multiplied
Returns
multiplied matrix

References isEmpty().

Referenced by lup().

double DUNE::Math::Matrix::norm_2 ( void  ) const
double DUNE::Math::Matrix::norm_inf ( void  ) const

This implements the infinity-norm.

Returns
resultant norm

References isEmpty().

double DUNE::Math::Matrix::norm_p ( double  p) const

This method implements the p-norm for both matrices and vectors.

The following values of p yield particular cases: Vectors: p = 1: Manhattan/taxicab norm; p = 2: Euclidean norm; very large values of p: infinity/maximum norm; Matrices: p = 2: Froebnius norm; very large values of p: maximum norm;

Parameters
[in]pnorm value
Returns
resultant norm

References isEmpty().

Referenced by expmts().

Matrix & DUNE::Math::Matrix::operator&= ( const Matrix m)

This methods multiplies each entry of a Matrix by the corresponding entry of another Matrix.

Parameters
[in]mreference to matrix to be multiplied
Returns
reference to resultant matrix
double & DUNE::Math::Matrix::operator() ( size_t  i,
size_t  j 
)

This operator returns a reference to a given entry of a Matrix.

As this methods makes possible to change the entries of a Matrix a spliting is necessary to avoid corrupting other matrices sharing the same data.

Note: As this method returns a reference it is very powerful, and it can be used to gain access to the pointer to the Matrix entries. This use can be dangerous because the data of a given matrix can move from place to place due to splitting.

Parameters
[in]irow index
[in]jcolumn index
Returns
reference to entry of a matrix

References isEmpty().

double DUNE::Math::Matrix::operator() ( size_t  i,
size_t  j 
) const

This routine returns a value of the matrix.

Parameters
[in]irow index
[in]jcolumn index
Returns
value of matrix

References isEmpty().

double & DUNE::Math::Matrix::operator() ( size_t  i)

This operator returns a reference to a given entry of a Matrix.

As this methods makes possible to change the entries of a Matrix a spliting is necessary to avoid corrupting other matrices sharing the same data.

Note: As this method returns a reference it is very powerful, and it can be used to gain access to the pointer to the Matrix entries. This use can be dangerous because the data of a given matrix can move from place to place due to splitting.

Parameters
[in]imatrix index
Returns
reference to entry of a matrix

References isEmpty().

double DUNE::Math::Matrix::operator() ( size_t  i) const

This routine returns a value of the matrix.

Parameters
[in]imatrix index
Returns
value of matrix

References isEmpty().

Matrix & DUNE::Math::Matrix::operator*= ( double  x)

This method multiplies a Matrix by a real number.

Parameters
[in]xreal number
Returns
reference to resultant matrix
Matrix & DUNE::Math::Matrix::operator+= ( const Matrix m)

This methods adds to a Matrix the contents of another Matrix.

Parameters
[in]mreference to matrix to be added
Returns
reference to resultant matrix
Matrix DUNE::Math::Matrix::operator- ( void  )

This method implements the unary minus operator.

Returns
resultant matrix

References isEmpty().

Matrix & DUNE::Math::Matrix::operator-= ( const Matrix m)

This methods subtracts from a Matrix the contents of another Matrix.

Parameters
[in]mreference to matrix to be subtracted
Returns
reference to resultant matrix
Matrix & DUNE::Math::Matrix::operator/= ( const Matrix m)

This methods divides each entry of Matrix by the correspondig entry of another Matrix.

Parameters
[in]mreference to matrix to be divided
Returns
reference to resultant matrix
Matrix & DUNE::Math::Matrix::operator/= ( double  x)

This method divides a Matrix by a real number.

Care must be taken to avoid divisions by zero.

Parameters
[in]xreal number
Returns
reference to resultant matrix
Matrix & DUNE::Math::Matrix::operator= ( const Matrix m)

This method assigns a Matrix with another Matrix.

The silly assignement 'a = a' is handled correctly (nothing is done!).

Parameters
[in]mreference to matrix to be assigned
Returns
reference to resultant matrix
bool DUNE::Math::Matrix::operator== ( const Matrix m) const

Compare matrices for equality.

Parameters
[in]mmatrix to compare.
Returns
true if matrices are equal, false otherwise.
Matrix & DUNE::Math::Matrix::pow ( unsigned int  n)

Returns the power matrix X^n.

Parameters
[in]npositive integer exponent to raise the matrix to
Returns
reference to the power of the matrix
void DUNE::Math::Matrix::put ( size_t  i,
size_t  j,
const Matrix a 
)

This method fills a submatrix of a given Matrix.

Parameters
[in]irow index
[in]jcolumn index
[in]asubmatrix

References isEmpty().

Referenced by mminor(), swapColumns(), and swapRows().

void DUNE::Math::Matrix::readFromConfig ( DUNE::Parsers::Config cfg,
const std::string &  section,
const std::string &  param 
)

Read a matrix from a configuration file.

The matrix dimensions must be defined a priori.

Parameters
[in]cfgconfiguration parser
[in]sectionconfiguration section
[in]paramconfiguration parameter

References DUNE::Parsers::Config::get(), and readFromLines().

Referenced by DUNE::Parsers::PlanConfigParser::parse().

void DUNE::Math::Matrix::readFromLines ( const std::vector< std::string > &  clines)

Read a matrix from a vector of strings The matrix dimensions must be defined a priori.

Parameters
[in]clinesvector of strings containing the matrix data

References isEmpty(), DUNE::Utils::String::split(), and DUNE::Utils::String::str().

Referenced by readFromConfig().

void DUNE::Math::Matrix::resize ( const Matrix m)

This method resizes a Matrix to the same dimensions of other matrix.

Note that no data copy is performed.

Parameters
[in]mreference to matrix

Referenced by fill(), resizeAndFill(), resizeAndKeep(), DUNE::Math::QPSolver::solve(), and Sensors::IFOG::Task::Task().

void DUNE::Math::Matrix::resize ( size_t  r,
size_t  c 
)

This method resizes a Matrix to the dimensions of (r * c).

Parameters
[in]rnumber of rows
[in]cnumber of columns
void DUNE::Math::Matrix::resizeAndFill ( size_t  r,
size_t  c,
double  value 
)

This method resizes a Matrix to the dimensions of (r * c) and fills the matrix with constant value.

Parameters
[in]rnumber of rows
[in]cnumber of columns
[in]valueconstant value to fill matrix with

References fill(), and resize().

Referenced by blkDiag(), DUNE::Navigation::CompassCalibration::clear(), cross(), horzCat(), DUNE::Navigation::KalmanFilter::KalmanFilter(), DUNE::Control::LinearSystem::LinearSystem(), mminor(), DUNE::Navigation::KalmanFilter::reset(), and vertCat().

void DUNE::Math::Matrix::resizeAndKeep ( size_t  r,
size_t  c 
)

This method resizes a Matrix to the dimensions of (r * c) and keeps previous matrix values if/when possible.

Parameters
[in]rnumber of rows
[in]cnumber of columns

References fill(), isEmpty(), and resize().

Referenced by Maneuver::VehicleFormation::FormCollAvoid::Task::consume(), Maneuver::VehicleFormation::Coordinator::Task::onUpdateParameters(), Maneuver::VehicleFormation::FormCollAvoid::Task::onUpdateParameters(), and DUNE::Navigation::KalmanFilter::resize().

Matrix DUNE::Math::Matrix::row ( size_t  i) const

This method returns a row of the Matrix.

Parameters
[in]irow to be retrieved
Returns
matrix of the returned row

Referenced by Maneuver::VehicleFormation::FormCollAvoid::Task::formationControl(), and swapRows().

void DUNE::Math::Matrix::set_precision ( double  p)
static

This method sets the precision used when inverting a Matrix.

Parameters
[in]pvalue of the precision to be used when inverting
void DUNE::Math::Matrix::swapColumns ( size_t  i,
size_t  j 
)

This method swaps two columns.

Parameters
[in]iindex of column
[in]jindex of column

References column(), and put().

void DUNE::Math::Matrix::swapRows ( size_t  i,
size_t  j 
)

This method swaps two rows.

Parameters
[in]iindex of row
[in]jindex of row

References put(), and row().

Referenced by lup().

bool DUNE::Math::Matrix::Sylvester ( void  ) const

Sylvester's criterion implementation.

Returns
true if success, false otherwise

References det(), isEmpty(), and mminor().

void DUNE::Math::Matrix::to_column ( void  )

This method changes the dimensions of a Matrix to a one column Matrix.

The elements are not changed.

void DUNE::Math::Matrix::to_row ( void  )

This method changes the dimensions of a Matrix to a one row Matrix.

The elements are not changed.

Matrix DUNE::Math::Matrix::toDCM ( void  ) const
Matrix DUNE::Math::Matrix::toEulerAngles ( void  ) const

Convert from DCM or Quaternion to Euler angles attitude representation.

Returns
Euler Angles representation

References element(), isEmpty(), and Matrix().

void DUNE::Math::Matrix::toFile ( const char *  path)

Saves matrix to text file.

Parameters
[in]pathfile path string (eg: "E:\dir/x.txt").
Matrix DUNE::Math::Matrix::toQuaternion ( void  ) const

Convert from DCM or Euler angles to Quaternion attitude representation.

Returns
Quaternion representation

References element(), isEmpty(), and Matrix().

double DUNE::Math::Matrix::trace ( void  ) const

Compute matrix trace (sum of diagonal elements for a square matrix).

Returns
trace of matrix

References isEmpty(), and isSquare().

void DUNE::Math::Matrix::trimValues ( double  min,
double  max 
)

Limit the minimum and maximum Matrix elements' values.

Parameters
[in]minminimum value
[in]maxmaximum value

References maxLimitValues(), and minLimitValues().

void DUNE::Math::Matrix::trimValues ( double  lim)

Limit the minimum and maximum Matrix elements' values.

Parameters
[in]limabsolute limit value

References maxLimitValues(), and minLimitValues().

int DUNE::Math::Matrix::upper_triangular_pp ( double *  M,
int  n,
int  m,
double  tolerance 
)
static

This function tranforms a Matrix 'M' (n*m) into an upper triangular Matrix using Gauss elimination with partial pivoting.

'm' should be >= 'n'.

Parameters
[out]Mmatrix to be transformed
[in]mnumber of columns
[in]nnumber of rows
[in]tolerancesmall positive constant used to test for zero entries in 'M'
Returns
0 if elimination done successfully, -1 if Matrix M is not full rank (elimination impossible)

Referenced by DUNE::Math::inverse_pp(), and isInvertible().

int DUNE::Math::Matrix::upper_triangular_tp ( double *  M,
int *  index,
int  n,
int  m,
double  tolerance 
)
static

This function tranforms a Matrix 'M' (n*m) into an upper triangular Matrix using Gauss elimination with total pivoting.

'm' should be >= 'n'.

The parameter 'index' is a pointer to an array of 'n' integers that indicates the permutations that are done during total pivotation. When this function is called the 'index' array must be properly initialized, i.e. ind[0]=0, ind[1]=1, ..., ind[n-1]=n-1.

Parameters
[out]Mmatrix to be transformed
[out]indexpointer to array that indicates permutations
[in]mnumber of columns
[in]nnumber of rows
[in]tolerancesmall positive constant used to test for zero entries in 'M'
Returns
0 if elimination done successfully, -1 if matrix is not full rank (elimination impossible)

Referenced by DUNE::Math::inverse().

Matrix & DUNE::Math::Matrix::vertCat ( const Matrix m_in)

Returns the vertical concatenation of a matrix Return a matrix of size (nrows + rows(m_in)) x (ncolumns) and fills the remaining elements with zeros.

Parameters
[in]m_inreference to matrix
Returns
reference to vertical concatenation of matrix

References columns(), isEmpty(), resizeAndFill(), rows(), and set().

Referenced by DUNE::Control::LinearSystem::append(), Simulators::UAV::Task::matrixJ(), Maneuver::VehicleFormation::FormCollAvoid::Task::onUpdateParameters(), DUNE::Math::operator>>(), Maneuver::VehicleFormation::Coordinator::Task::setLeaderState(), and Maneuver::VehicleFormation::FormCollAvoid::Task::setLeaderState().

Friends And Related Function Documentation

Matrix abs ( const Matrix a)
friend

This function returns a Matrix with the absolute values of the entries of a given Matrix.

Parameters
[in]amatrix
Returns
matrix with absolute values
DUNE_DLL_SYM Matrix inverse ( const Matrix a)
friend

This methods calculates the inverse of a Matrix.

The inverse is calculated using Gauss elimination with total pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'a' is returned and the variable 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix to be inverted.
Returns
inverted matrix
DUNE_DLL_SYM Matrix inverse ( const Matrix a,
const Matrix b 
)
friend

This methods calculates the Matrix 'x' that solves the linear system of equations 'a.x=b'.

The system is solved using Gauss elimination with total pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'b' is returned and the variable 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix
[in]bmatrix
Returns
resultant matrix
Matrix inverse_lup ( const Matrix a)
friend

This function computes the Matrix inverse using LU or LUP decomposition.

Parameters
[in]areference to matrix to be inverted
Returns
inverted matrix
Matrix inverse_pp ( const Matrix a)
friend

This methods calculates the inverse of a Matrix.

The inverse is calculated using Gauss elimination with partial pivoting.

If Matrix is singular (with current precision) a zero Matrix with the same dimension is returned and the variable. 'dMatrix::inversionerror' is set to 1. Otherwise is is set to 0.

Parameters
[in]areference to matrix to be inverted
Returns
inverted matrix
Matrix inverse_pp ( const Matrix a,
const Matrix b 
)
friend

This methods calculates the Matrix 'x' that solves the linear system of equations 'a.x=b'.

The system is solved using Gauss elimination with partial pivoting.

If Matrix 'a' is singular (with current precision) a zero Matrix with the same dimension of 'b' is returned and the variable. 'dMatrix::inversionerror' is set to 1. Otherwise it is set to 0.

Parameters
[in]amatrix
[in]bmatrix
Returns
resultant matrix
double max ( const Matrix a)
friend

This function returns the maximum value of a Matrix.

Parameters
[in]amatrix
Returns
maximum value of matrix

Referenced by maxLimitValues().

double min ( const Matrix a)
friend

This function returns the minimum value of a Matrix.

Parameters
[in]amatrix
Returns
minimum value of matrix

Referenced by minLimitValues().

DUNE_DLL_SYM Matrix operator& ( const Matrix m1,
const Matrix m2 
)
friend

This method returns the element-element product of two matrices.

Parameters
[in]m1matrix to be multiplied (element-element).
[in]m2matrix to be multiplied (element-element).
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator* ( const Matrix m1,
const Matrix m2 
)
friend

This method returns the product of two matrices.

Note on optimization by Eduardo Marques - Sep 8 2010

Applied loop interchange to achieve memory stride 1 (better data locality) in iterations of the innermost loop, This makes for better cache behavior (i.e. less cache misses), particularly as matrix dimensions increase. For those interested, see papers or books by M J Wolfe.

Parameters
[in]m1matrix to be summed.
[in]m2matrix to be summed.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator* ( double  x,
const Matrix a 
)
friend

This function multiplies a Matrix by a real number.

Parameters
[in]xreal number.
[in]amatrix to be multiplied.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator* ( const Matrix a,
double  x 
)
friend

This function multiplies a Matrix by a real number.

Parameters
[in]amatrix to be multiplied.
[in]xreal number.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator+ ( const Matrix m1,
const Matrix m2 
)
friend

This method returns the sum of two matrices.

Parameters
[in]m1matrix to be summed.
[in]m2matrix to be summed.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator- ( const Matrix m1,
const Matrix m2 
)
friend

This method returns the difference of two matrices.

Parameters
[in]m1matrix to be subtracted.
[in]m2matrix to subtract.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator/ ( const Matrix a,
const Matrix b 
)
friend

This method returns the element-element quocient of two matrices.

Parameters
[in]amatrix for element-element quocient.
[in]bmatrix for element-element quocient.
Returns
resultant matrix.
DUNE_DLL_SYM Matrix operator/ ( const Matrix a,
double  x 
)
friend

This function divides a Matrix by a real number.

Parameters
[in]amatrix to be divided.
[in]xreal number.
Returns
resultant matrix.
DUNE_DLL_SYM std::ostream& operator<< ( std::ostream &  os,
const Matrix a 
)
friend

This method sends a Matrix to an 'ostream'.

Each row of the Matrix is put on a different line.

Parameters
[in]osoutput stream.
[in]amatrix to be outputted.
DUNE_DLL_SYM std::istream& operator>> ( std::istream &  is,
Matrix a 
)
friend

This method reads a Matrix from an 'istream'.

The Matrix is filled row by row.

Parameters
[in]isinput stream.
[in]amatrix to be filled.
Returns
resultant matrix.
Matrix skew ( double  data[3])
friend

This function returns a 3x3 skew symmetrical matrix using an array with 3 elements.

Parameters
[in]dataarray with 3 elements
Returns
skewed matrix

Referenced by DUNE::Math::skew().

Matrix skew ( const Matrix a)
friend

This function returns a 3x3 skew symmetrical matrix using a matrix (3x1 or 1x3)

Parameters
[in]arow or column vector with 3 elements
Returns
skewed matrix
double squaresum ( const Matrix a)
friend

This function returns the sum of the squares of the elements of a given Matrix.

Parameters
[in]amatrix
Returns
squared sum of the elements of matrix
double sum ( const Matrix a)
friend

This function returns the sum of the elements of a given Matrix.

Parameters
[in]amatrix
Returns
sum of the elements of matrix
DUNE_DLL_SYM Matrix transpose ( const Matrix a)
friend

This method returns the transpose of a Matrix.

Parameters
[in]ato be transposed.
Returns
transposed matrix.

Referenced by toDCM().

Collaboration diagram for DUNE::Math::Matrix:
Collaboration graph