ViSP  2.8.0
vpMatrix Class Reference

#include <vpMatrix.h>

+ Inheritance diagram for vpMatrix:

Public Types

enum  vpDetMethod { LU_DECOMPOSITION }
 

Public Member Functions

 vpMatrix ()
 
 vpMatrix (unsigned int r, unsigned int c)
 
 vpMatrix (const vpMatrix &m, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
 
virtual ~vpMatrix ()
 
void init ()
 
void kill ()
 
void eye (unsigned int n)
 
void eye (unsigned int m, unsigned int n)
 
void setIdentity (const double &val=1.0)
 
void stackMatrices (const vpMatrix &A)
 
void insert (const vpMatrix &A, const unsigned int r, const unsigned int c)
 
Set/get Matrix size
unsigned int getRows () const
 
unsigned int getCols () const
 
void resize (const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
 
double getMinValue () const
 
double getMaxValue () const
 
Printing
int print (std::ostream &s, unsigned int length, char const *intro=0)
 
std::ostream & matlabPrint (std::ostream &os)
 
std::ostream & maplePrint (std::ostream &os)
 
std::ostream & cppPrint (std::ostream &os, const char *matrixName=NULL, bool octet=false)
 
void printSize ()
 
Copy / assignment
 vpMatrix (const vpMatrix &m)
 
vpMatrixoperator<< (double *)
 
vpMatrixoperator= (const vpMatrix &B)
 
vpMatrixoperator= (const double x)
 
void diag (const vpColVector &A)
 
Access/modification operators
double * operator[] (unsigned int n)
 
double * operator[] (unsigned int n) const
 
Matrix operations
vpMatrixoperator+= (const vpMatrix &B)
 
vpMatrixoperator-= (const vpMatrix &B)
 
vpMatrix operator* (const vpMatrix &B) const
 
vpMatrix operator+ (const vpMatrix &B) const
 
vpMatrix operator- (const vpMatrix &B) const
 
vpMatrix operator- () const
 
vpColVector operator* (const vpColVector &b) const
 
vpTranslationVector operator* (const vpTranslationVector &b) const
 
vpMatrixoperator+= (const double x)
 
vpMatrixoperator-= (const double x)
 
vpMatrixoperator*= (const double x)
 
vpMatrixoperator/= (double x)
 
vpMatrix operator* (const double x) const
 
vpMatrix operator/ (const double x) const
 
double sumSquare () const
 
double det (vpDetMethod method=LU_DECOMPOSITION) const
 
vpMatrix expm ()
 
Columns, Rows extraction, Submatrix
vpRowVector row (const unsigned int i)
 
vpColVector column (const unsigned int j)
 
void init (const vpMatrix &m, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
 
Transpose, Identity
vpMatrix t () const
 
vpMatrix transpose () const
 
void transpose (vpMatrix &C) const
 
vpMatrix AAt () const
 
void AAt (vpMatrix &B) const
 
vpMatrix AtA () const
 
void AtA (vpMatrix &B) const
 
Kronecker product
void stackColumns (vpColVector &out)
 
vpColVector stackColumns ()
 
void stackRows (vpRowVector &out)
 
vpRowVector stackRows ()
 
void kron (const vpMatrix &m1, vpMatrix &out)
 
vpMatrix kron (const vpMatrix &m1)
 
Matrix inversion
vpMatrix inverseByLU () const
 
vpMatrix inverseByCholesky () const
 
vpMatrix inverseByCholeskyLapack () const
 
vpMatrix inverseByQR () const
 
vpMatrix inverseByQRLapack () const
 
vpMatrix pseudoInverse (double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold=1e-6) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &ImA, vpMatrix &ImAt) const
 
unsigned int pseudoInverse (vpMatrix &Ap, vpColVector &sv, double svThreshold, vpMatrix &ImA, vpMatrix &ImAt, vpMatrix &kerA) const
 
SVD decomposition
void svd (vpColVector &w, vpMatrix &v)
 
void solveBySVD (const vpColVector &B, vpColVector &x) const
 
vpColVector solveBySVD (const vpColVector &B) const
 
unsigned int kernel (vpMatrix &KerA, double svThreshold=1e-6)
 
Eigen values
vpColVector eigenValues ()
 
void eigenValues (vpColVector &evalue, vpMatrix &evector)
 
Norms
double euclideanNorm () const
 
double infinityNorm () const
 

Static Public Member Functions

static bool saveMatrix (const char *filename, const vpMatrix &M, const bool binary=false, const char *Header="")
 
static bool loadMatrix (const char *filename, vpMatrix &M, const bool binary=false, char *Header=NULL)
 
static bool saveMatrix (std::string filename, const vpMatrix &M, const bool binary=false, const char *Header="")
 
static bool loadMatrix (std::string filename, vpMatrix &M, const bool binary=false, char *Header=NULL)
 
static void mult2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void add2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void add2WeightedMatrices (const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, vpMatrix &C)
 
static void sub2Matrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void negateMatrix (const vpMatrix &A, vpMatrix &C)
 
static void multMatrixVector (const vpMatrix &A, const vpColVector &b, vpColVector &c)
 
static vpMatrix computeCovarianceMatrix (const vpMatrix &A, const vpColVector &x, const vpColVector &b)
 
static vpMatrix computeCovarianceMatrix (const vpMatrix &A, const vpColVector &x, const vpColVector &b, const vpMatrix &w)
 
static void kron (const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out)
 
static vpMatrix kron (const vpMatrix &m1, const vpMatrix &m2)
 
static vpMatrix stackMatrices (const vpMatrix &A, const vpMatrix &B)
 
static void stackMatrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static vpMatrix juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B)
 
static void juxtaposeMatrices (const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
 
static void createDiagonalMatrix (const vpColVector &A, vpMatrix &DA)
 
static vpMatrix insert (const vpMatrix &A, const vpMatrix &B, const unsigned int r, const unsigned int c)
 
static void insert (const vpMatrix &A, const vpMatrix &B, vpMatrix &C, const unsigned int r, const unsigned int c)
 

Public Attributes

double * data
 

Protected Attributes

unsigned int rowNum
 
unsigned int colNum
 
double ** rowPtrs
 
unsigned int dsize
 
unsigned int trsize
 

Friends

VISP_EXPORT std::ostream & operator<< (std::ostream &s, const vpMatrix &m)
 

Related Functions

(Note that these are not member functions.)

enum  vpGEMMmethod
 
void vpGEMM (const vpMatrix &A, const vpMatrix &B, const double &alpha, const vpMatrix &C, const double &beta, vpMatrix &D, const unsigned int &ops=0)
 
vpMatrix operator* (const double &x, const vpMatrix &B)
 
void skew (const vpTranslationVector &t, vpMatrix &M)
 

Detailed Description

Definition of the vpMatrix class.

vpMatrix class provides a data structure for the matrices as well as a set of operations on these matrices

Author
Eric Marchand (IRISA - INRIA Rennes)
Warning
Note the matrix in the class (*this) will be noted A in the comment
See also
vpRowVector, vpColVector, vpHomogeneousMatrix, vpRotationMatrix, vpTwistMatrix, vpHomography
Examples:
manServo4PointsDisplay.cpp, manSimu4Dots.cpp, manSimu4Points.cpp, photometricVisualServoing.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocityKalman.cpp, servoAfma6FourPoints2DArtVelocity.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoBiclopsPoint2DArtVelocity.cpp, servoMomentImage.cpp, servoPioneerPanSegment3D.cpp, servoPioneerPoint2DDepth.cpp, servoPioneerPoint2DDepthWithoutVpServo.cpp, servoPtu46Point2DArtVelocity.cpp, servoSimu3D_cMcd_CamVelocityWithoutVpServo.cpp, servoSimu4Points.cpp, servoSimuCylinder.cpp, servoSimuFourPoints2DCamVelocity.cpp, servoSimuFourPoints2DCamVelocityDisplay.cpp, servoSimuFourPoints2DPolarCamVelocityDisplay.cpp, servoSimuPoint2DCamVelocity2.cpp, servoSimuPoint2DCamVelocity3.cpp, servoSimuPoint2DhalfCamVelocity2.cpp, servoSimuSphere.cpp, servoViper650FourPoints2DArtVelocityInteractionCurrent.cpp, servoViper850FourPoints2DArtVelocityInteractionCurrent.cpp, servoViper850FourPoints2DArtVelocityInteractionDesired.cpp, servoViper850Point2DArtVelocity-jointAvoidance-basic.cpp, servoViper850Point2DArtVelocity-jointAvoidance-gpa.cpp, servoViper850Point2DArtVelocity.cpp, servoViper850Point2DCamVelocityKalman.cpp, simulateFourPoints2DCartesianCamVelocity.cpp, simulateFourPoints2DPolarCamVelocity.cpp, testFeature.cpp, testMatrix.cpp, testMatrixException.cpp, testMatrixInverse.cpp, testPoseFeatures.cpp, testSvd.cpp, tutorial-simu-pioneer-pan.cpp, and tutorial-simu-pioneer.cpp.

Definition at line 96 of file vpMatrix.h.

Member Enumeration Documentation

Method used to compute the determinant of a square matrix.

See also
det()
Enumerator
LU_DECOMPOSITION 

LU decomposition method.

Definition at line 103 of file vpMatrix.h.

Constructor & Destructor Documentation

vpMatrix::vpMatrix ( )

Basic constructor.

basic constructor of the matrix class Construction of the object matrix. Number of columns and rows are zero.

Definition at line 111 of file vpMatrix.cpp.

References init().

Referenced by vpHomography::computeDisplacement(), vpHomography::HartleyDenormalization(), and vpColVector::operator*().

vpMatrix::vpMatrix ( unsigned int  r,
unsigned int  c 
)

Constructor. Initialization of A as an r x c matrix with 0.

Constructor.

Initialize a matrix with 0.

Parameters
r: Matrix number of rows.
c: Matrix number of columns.

Definition at line 125 of file vpMatrix.cpp.

References init(), and resize().

vpMatrix::vpMatrix ( const vpMatrix m,
unsigned int  r,
unsigned int  c,
unsigned int  nrows,
unsigned int  ncols 
)

sub vpMatrix constructor

submatrix constructor

Definition at line 134 of file vpMatrix.cpp.

References colNum, init(), rowNum, vpMatrixException::subMatrixError, and vpERROR_TRACE.

vpMatrix::~vpMatrix ( )
virtual

Destructor (Memory de-allocation)

Definition at line 303 of file vpMatrix.cpp.

References kill().

vpMatrix::vpMatrix ( const vpMatrix m)

Copy constructor.

copie constructor

Definition at line 151 of file vpMatrix.cpp.

References colNum, data, init(), resize(), and rowNum.

Member Function Documentation

vpMatrix vpMatrix::AAt ( ) const

Computes the $AA^T$ operation $B = A*A^T$

Returns
$A*A^T$
See also
AAt(vpMatrix &) const

Definition at line 1248 of file vpMatrix.cpp.

void vpMatrix::AAt ( vpMatrix B) const

Compute the AAt operation such as $B = A*A^T$.

The result is placed in the parameter B and not returned.

A new matrix won't be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.

See also
AAt()

Definition at line 1268 of file vpMatrix.cpp.

References colNum, resize(), rowNum, rowPtrs, vpCERROR, and vpERROR_TRACE.

void vpMatrix::add2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A + B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator+()

Definition at line 493 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

Referenced by operator+().

void vpMatrix::add2WeightedMatrices ( const vpMatrix A,
const double &  wA,
const vpMatrix B,
const double &  wB,
vpMatrix C 
)
static

Operation C = A*wA + B*wB

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator+()

Definition at line 454 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

vpMatrix vpMatrix::AtA ( ) const
void vpMatrix::AtA ( vpMatrix B) const

Compute the AtA operation such as $B = A^T*A$.

The result is placed in the parameter B and not returned.

A new matrix won't be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.

See also
AtA()

Definition at line 1311 of file vpMatrix.cpp.

References colNum, data, resize(), rowNum, vpCERROR, and vpERROR_TRACE.

vpColVector vpMatrix::column ( const unsigned int  j)

Column extraction.

Return the ith columns of the matrix.

Warning
notice column(1) is the 0th column.

Definition at line 2240 of file vpMatrix.cpp.

References getRows().

Referenced by vpHomography::DLT(), vpPose::poseDementhonPlan(), and vpPose::poseFromRectangle().

vpMatrix vpMatrix::computeCovarianceMatrix ( const vpMatrix A,
const vpColVector x,
const vpColVector b 
)
static

Compute the covariance matrix of the parameters x from a least squares minimisation defined as: Ax = b

Parameters
A: Matrix A from Ax = b.
x: Vector x from Ax = b corresponding to the parameters to estimate.
b: Vector b from Ax = b.

Definition at line 56 of file vpMatrix_covariance.cpp.

References pseudoInverse(), vpColVector::t(), and t().

Referenced by vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), vpMbEdgeTracker::computeVVS(), vpPose::poseVirtualVS(), and vpPose::poseVirtualVSrobust().

vpMatrix vpMatrix::computeCovarianceMatrix ( const vpMatrix A,
const vpColVector x,
const vpColVector b,
const vpMatrix W 
)
static

Compute the covariance matrix of the parameters x from a least squares minimisation defined as: WAx = Wb

Parameters
A: Matrix A from WAx = Wb.
x: Vector x from WAx = Wb corresponding to the parameters to estimate.
b: Vector b from WAx = Wb.
W: Diagonal weigths matrix from WAx = Wb.

Definition at line 74 of file vpMatrix_covariance.cpp.

References pseudoInverse(), and t().

std::ostream & vpMatrix::cppPrint ( std::ostream &  os,
const char *  matrixName = NULL,
bool  octet = false 
)

Print to be used as part of a C++ code later.

Print under the following form: vpMatrix A(6,4); A[0][0] = 1.4; A[0][1] = 0.6; ...

Parameters
osthe stream to be printed in.
matrixNamename of the matrix, "A" by default, to be used for the line vpMatrix A(6,7) (see example).
octetif false, print using double, if true, print byte per byte each bytes of the double array.

Definition at line 2768 of file vpMatrix.cpp.

References getRows().

void vpMatrix::createDiagonalMatrix ( const vpColVector A,
vpMatrix DA 
)
static

Create a diagonal matrix with the element of a vector $ DA_{ii} = A_i $.

Parameters
A: Vector which element will be put in the diagonal.
DA: Diagonal matrix DA[i][i] = A[i]
See also
diag()

Definition at line 2551 of file vpMatrix.cpp.

References getRows(), resize(), vpCERROR, and vpERROR_TRACE.

double vpMatrix::det ( vpDetMethod  method = LU_DECOMPOSITION) const

Compute the determinant of a n-by-n matrix.

Parameters
method: Method used to compute the determinant. Default LU decomposition methos is faster than the method based on Gaussian elimination.
Returns
Determinant of the matrix.
#include <iostream>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.;
std::cout << "Initial matrix: \n" << A << std::endl;
// Compute the determinant
std:: cout << "Determinant by default method : " <<
A.det() << std::endl;
std:: cout << "Determinant by LU decomposition: " <<
}
Examples:
testMatrixInverse.cpp.

Definition at line 3413 of file vpMatrix.cpp.

References LU_DECOMPOSITION.

Referenced by vpHomography::computeDisplacement().

void vpMatrix::diag ( const vpColVector A)

Create a diagonal matrix with the element of a vector.

Parameters
A: Vector which element will be put in the diagonal.
See also
createDiagonalMatrix()
#include <iostream>
#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
v[0] = 1;
v[1] = 2;
v[2] = 3;
A.diag(v);
std::cout << "A:\n" << A << std::endl;
// A is now equal to:
// 1 0 0
// 0 2 0
// 0 0 3
}

Definition at line 2523 of file vpMatrix.cpp.

References getRows(), resize(), vpCERROR, and vpERROR_TRACE.

Referenced by vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), and vpMbEdgeTracker::computeVVS().

vpColVector vpMatrix::eigenValues ( )

Compute the eigenvalues of a n-by-n real symmetric matrix.

Returns
The eigenvalues of a n-by-n real symmetric matrix.
Warning
This method is only available if the Gnu Scientific Library (GSL) is detected as a third party library.
Exceptions
vpMatrixException::matrixErrorIf the matrix is not square or if the matrix is not symmetric.
vpMatrixException::notImplementedErrorIf the GSL library is not detected

Here an example:

#include <iostream>
#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(3,3); // A is a symmetric matrix
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.;
A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.;
A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.;
std::cout << "Initial symmetric matrix: \n" << A << std::endl;
// Compute the eigen values
vpColVector evalue; // Eigenvalues
evalue = A.eigenValues();
std::cout << "Eigen values: \n" << evalue << std::endl;
}
See also
eigenValues(vpColVector &, vpMatrix &)

Definition at line 2996 of file vpMatrix.cpp.

References colNum, vpMatrixException::matrixError, vpMatrixException::notImplementedError, rowNum, t(), and vpERROR_TRACE.

void vpMatrix::eigenValues ( vpColVector evalue,
vpMatrix evector 
)

Compute the eigenvalues of a n-by-n real symmetric matrix.

Returns
The eigenvalues of a n-by-n real symmetric matrix.
Warning
This method is only available if the Gnu Scientific Library (GSL) is detected as a third party library.
Parameters
evalue: Eigenvalues of the matrix.
evector: Eigenvector of the matrix.
Exceptions
vpMatrixException::matrixErrorIf the matrix is not square or if the matrix is not symmetric.
vpMatrixException::notImplementedErrorIf the GSL library is not detected

Here an example:

#include <iostream>
#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(4,4); // A is a symmetric matrix
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.; A[1][3] = 1/5.;
A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.; A[2][3] = 1/6.;
A[3][0] = 1/4.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
std::cout << "Initial symmetric matrix: \n" << A << std::endl;
vpColVector d; // Eigenvalues
vpMatrix V; // Eigenvectors
// Compute the eigenvalues and eigenvectors
A.eigenValues(d, V);
std::cout << "Eigen values: \n" << d << std::endl;
std::cout << "Eigen vectors: \n" << V << std::endl;
D.diag(d); // Eigenvalues are on the diagonal
std::cout << "D: " << D << std::endl;
// Verification: A * V = V * D
std::cout << "AV-VD = 0 ? \n" << (A*V) - (V*D) << std::endl;
}
See also
eigenValues()

Definition at line 3115 of file vpMatrix.cpp.

References colNum, data, vpMatrixException::matrixError, vpMatrixException::notImplementedError, vpColVector::resize(), resize(), rowNum, t(), and vpERROR_TRACE.

double vpMatrix::euclideanNorm ( ) const

Compute and return the Euclidean norm $ ||x|| = \sqrt{ \sum{x_{ij}^2}} $.

Returns
The Euclidean norm if the matrix is initialized, 0 otherwise.
See also
infinityNorm()

Definition at line 2816 of file vpMatrix.cpp.

References data, and dsize.

Referenced by vpSimulatorAfma6::setPosition().

vpMatrix vpMatrix::expm ( )

Compute the exponential matrix of a square matrix.

Returns
Return the exponential matrix.

Definition at line 3600 of file vpMatrix.cpp.

References colNum, vpMatrixException::incorrectMatrixSizeError, inverseByLU(), rowNum, setIdentity(), and vpTRACE.

void vpMatrix::eye ( unsigned int  n)

Set an n-by-n matrix to identity.

eye(n) is an n-by-n matrix with ones on the diagonal and zeros else where.

Examples:
testMatrix.cpp.

Definition at line 1132 of file vpMatrix.cpp.

References vpCERROR, and vpERROR_TRACE.

Referenced by vpServo::setServo().

void vpMatrix::eye ( unsigned int  m,
unsigned int  n 
)

Set an m-by-n matrix to identity.

eye(m,n) is an m-by-n matrix with ones on the diagonal and zeros else where.

Definition at line 1152 of file vpMatrix.cpp.

References colNum, resize(), rowNum, vpCERROR, and vpERROR_TRACE.

double vpMatrix::getMaxValue ( ) const
Examples:
servoMomentImage.cpp.

Definition at line 3685 of file vpMatrix.cpp.

References data, and dsize.

double vpMatrix::getMinValue ( ) const
Examples:
servoMomentImage.cpp.

Definition at line 3671 of file vpMatrix.cpp.

References data, and dsize.

unsigned int vpMatrix::getRows ( ) const
inline

Return the number of rows of the matrix.

Examples:
testMatrixInverse.cpp, and testSvd.cpp.

Definition at line 157 of file vpMatrix.h.

Referenced by add2Matrices(), add2WeightedMatrices(), vpLine::changeFrame(), vpSubColVector::checkParentStatus(), vpSubMatrix::checkParentStatus(), column(), vpServo::computeError(), vpServo::computeInteractionMatrix(), vpMbTracker::computeJTR(), vpPtu46::computeMGD(), vpPose::computeResidual(), vpHomography::computeResidual(), vpHomography::computeTransformation(), vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), vpMbEdgeTracker::computeVVS(), cppPrint(), createDiagonalMatrix(), vpColVector::crossProd(), vpDot2::defineDots(), vpHomography::degenerateConfiguration(), diag(), vpProjectionDisplay::display(), vpColVector::dotProd(), vpGenericFeature::error(), vpImageFilter::filter(), vpPtu46::get_eJe(), vpBiclops::get_eJe(), vpPtu46::get_fJe(), vpBiclops::get_fJe(), vpBiclops::get_fMe(), vpGenericFeature::get_s(), vpBasicFeature::getDimension(), vpImageSimulator::getImage(), vpAfma6::getInverseKinematics(), vpViper::getInverseKinematicsWrist(), vpSubColVector::init(), vpSubMatrix::init(), vpCameraParameters::initFromCalibrationMatrix(), insert(), vpFeatureLuminance::interaction(), vpGenericFeature::interaction(), inverseByCholeskyLapack(), inverseByLU(), inverseByQRLapack(), vpColVector::invSort(), juxtaposeMatrices(), kernel(), vpScale::KernelDensity(), vpScale::KernelDensityGradient(), kron(), maplePrint(), matlabPrint(), vpColVector::mean(), vpScale::MeanShift(), vpColVector::median(), vpRobust::MEstimator(), multMatrixVector(), vpRowVector::operator*(), vpRotationMatrix::operator*(), vpVelocityTwistMatrix::operator*(), vpForceTwistMatrix::operator*(), operator*(), operator+=(), operator-=(), vpColVector::operator<<(), vpSubColVector::operator=(), vpSubMatrix::operator=(), vpSubRowVector::operator=(), vpRotationMatrix::operator=(), vpColVector::operator=(), vpRGBa::operator=(), vpPlot::plot(), vpPose::poseDementhonPlan(), vpPose::poseVirtualVSrobust(), vpKalmanFilter::prediction(), print(), vpLine::projection(), pseudoInverse(), vpIoTools::readConfigVar(), vpRowVector::reshape(), vpColVector::reshape(), saveMatrix(), vpGenericFeature::set_s(), vpGenericFeature::setError(), vpGenericFeature::setInteractionMatrix(), vpSimulatorAfma6::setJointLimit(), vpSimulatorViper850::setJointLimit(), vpRobotBiclopsController::setPosition(), vpRobotAfma4::setPosition(), vpRobotBiclopsController::setVelocity(), vpRobotPtu46::setVelocity(), vpRobotBiclops::setVelocity(), vpSimulatorAfma6::setVelocity(), vpSimulatorViper850::setVelocity(), vpRobotAfma4::setVelocity(), vpLine::setWorldCoordinates(), vpRobust::simultMEstimator(), vpColVector::size(), vpColVector::skew(), vpColVector::sort(), vpColVector::stack(), stackMatrices(), sub2Matrices(), svd(), and vpColVector::vpColVector().

double vpMatrix::infinityNorm ( ) const

Compute and return the infinity norm $ {||x||}_{\infty} = max\left(\sum_{j=0}^{n}{\mid x_{ij} \mid}\right) $ with $i \in \{0, ..., m\}$ where $(m,n)$ is the matrix size.

Returns
The infinity norm if the matrix is initialized, 0 otherwise.
See also
euclideanNorm()

Definition at line 2840 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

void vpMatrix::init ( )

Initialization of the object matrix.

initialization of the object matrix. Number of columns and rows are zero.

Definition at line 93 of file vpMatrix.cpp.

References colNum, data, dsize, rowNum, rowPtrs, and trsize.

Referenced by vpColVector::vpColVector(), vpMatrix(), vpRotationVector::vpRotationVector(), vpSubColVector::vpSubColVector(), vpSubMatrix::vpSubMatrix(), vpSubRowVector::vpSubRowVector(), and vpTranslationVector::vpTranslationVector().

void vpMatrix::init ( const vpMatrix m,
unsigned int  r,
unsigned int  c,
unsigned int  nrows,
unsigned int  ncols 
)

subvpMatrix extraction

Definition at line 263 of file vpMatrix.cpp.

References resize(), and vpERROR_TRACE.

void vpMatrix::insert ( const vpMatrix A,
const unsigned int  r,
const unsigned int  c 
)

Insert matrix A at the given position in the current matrix.

Warning
Throw vpMatrixException::incorrectMatrixSizeError if the dimensions of the matrices do not allow the operation.
Parameters
A: The matrix to insert.
r: The index of the row to begin to insert data.
c: The index of the column to begin to insert data.

Definition at line 2939 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, and rowNum.

Referenced by vpNurbs::curveKnotIns(), insert(), vpPioneerPan::set_mMp(), and vpPioneerPan::set_pMe().

vpMatrix vpMatrix::insert ( const vpMatrix A,
const vpMatrix B,
const unsigned int  r,
const unsigned int  c 
)
static

Insert matrix B in matrix A at the given position.

Parameters
A: Main matrix.
B: Matrix to insert.
r: Index of the row where to add the matrix.
c: Index of the column where to add the matrix.
Returns
Matrix with B insert in A.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.

Definition at line 2348 of file vpMatrix.cpp.

References insert(), and vpCERROR.

void insert ( const vpMatrix A,
const vpMatrix B,
vpMatrix C,
const unsigned int  r,
const unsigned int  c 
)
static

Insert matrix B in matrix A at the given position.

Parameters
A: Main matrix.
B: Matrix to insert.
C: Result matrix.
r: Index of the row where to insert matrix B.
c: Index of the column where to insert matrix B.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.

Definition at line 2379 of file vpMatrix.cpp.

References getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), vpCERROR, and vpERROR_TRACE.

vpMatrix vpMatrix::inverseByCholesky ( ) const

Compute the inverse of a n-by-n matrix using the Cholesky decomposition. The matrix must be real and symmetric. Only available if lapack is installed.

Returns
The inverse matrix.

Here an example:

#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByCholesky();
std::cout << "Inverse by Cholesky: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See also
pseudoInverse()

Definition at line 124 of file vpMatrix_cholesky.cpp.

References colNum, inverseByCholeskyLapack(), vpMatrixException::matrixError, rowNum, and vpERROR_TRACE.

vpMatrix vpMatrix::inverseByCholeskyLapack ( ) const

Definition at line 62 of file vpMatrix_cholesky.cpp.

References vpException::badValue, data, getCols(), getRows(), and rowNum.

Referenced by inverseByCholesky().

vpMatrix vpMatrix::inverseByLU ( ) const

Compute the inverse of a n-by-n matrix using the LU decomposition.

Returns
The inverse matrix.

Here an example:

#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByLU();
std::cout << "Inverse by LU: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See also
pseudoInverse()
Examples:
photometricVisualServoing.cpp.

Definition at line 236 of file vpMatrix_lu.cpp.

References colNum, getRows(), vpMatrixException::matrixError, rowNum, and vpERROR_TRACE.

Referenced by expm(), and vpKalmanFilter::filtering().

vpMatrix vpMatrix::inverseByQR ( ) const

Compute the inverse of a n-by-n matrix using the QR decomposition. Only available if lapack is installed.

Returns
The inverse matrix.

Here an example:

#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.inverseByQR();
std::cout << "Inverse by QR: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See also
pseudoInverse()

Definition at line 226 of file vpMatrix_qr.cpp.

References colNum, inverseByQRLapack(), vpMatrixException::matrixError, rowNum, and vpERROR_TRACE.

vpMatrix vpMatrix::inverseByQRLapack ( ) const

Definition at line 73 of file vpMatrix_qr.cpp.

References vpException::badValue, colNum, data, getCols(), getRows(), and rowNum.

Referenced by inverseByQR().

vpMatrix vpMatrix::juxtaposeMatrices ( const vpMatrix A,
const vpMatrix B 
)
static

Juxtapose to matrices C = [ A B ].

$ C = \left( \begin{array}{cc} A & B \end{array}\right) $

Parameters
A: Left matrix.
B: Right matrix.
Returns
Juxtaposed matrix C = [ A B ]
Warning
A and B must have the same number of column

Definition at line 2422 of file vpMatrix.cpp.

References vpCERROR.

void juxtaposeMatrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Juxtapose to matrices C = [ A B ].

$ C = \left( \begin{array}{cc} A & B \end{array}\right) $

Parameters
A: Left matrix.
B: Right matrix.
C: Juxtaposed matrix C = [ A B ]
Warning
A and B must have the same number of column

Definition at line 2451 of file vpMatrix.cpp.

References getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), vpCERROR, and vpERROR_TRACE.

unsigned int vpMatrix::kernel ( vpMatrix kerA,
double  svThreshold = 1e-6 
)

Function to compute the null space (the kernel) of the interaction matrix A which is not full rank. The null space ( the kernel ) of a matrix A is defined as Null(A) = Ker(M) ={KerA : A*KerA =0}.

Parameters
kerA: The matrix to contain the null space (kernel) of A (A*KerA.t()=0)
svThreshold: Specify the used threshold in the svd(...) function (a function to compute the singular value decomposition)
Returns
the rank of the matrix.
Examples:
servoViper850Point2DArtVelocity-jointAvoidance-basic.cpp.

Definition at line 3217 of file vpMatrix.cpp.

References getCols(), getRows(), resize(), row(), sumSquare(), and svd().

void vpMatrix::kill ( )

Destruction of the matrix (Memory de-allocation)

Definition at line 286 of file vpMatrix.cpp.

References data, and rowPtrs.

Referenced by ~vpMatrix().

void vpMatrix::kron ( const vpMatrix m,
vpMatrix out 
)

Compute Kronecker product matrix.

Parameters
m: vpMatrix.
out: If m1.kron(m2) out contains the kronecker product's result : $ m1 \otimes m2 $.

Definition at line 1477 of file vpMatrix.cpp.

Referenced by kron().

vpMatrix vpMatrix::kron ( const vpMatrix m)

Compute Kronecker product matrix.

Parameters
m: vpMatrix;
Returns
m1.kron(m2) The kronecker product : $ m1 \otimes m2 $

Definition at line 1518 of file vpMatrix.cpp.

References kron().

void vpMatrix::kron ( const vpMatrix m1,
const vpMatrix m2,
vpMatrix out 
)
static

Compute Kronecker product matrix.

Parameters
m1: vpMatrix;
m2: vpMatrix;
out: The kronecker product : $ m1 \otimes m2 $

Definition at line 1443 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, rowNum, and vpERROR_TRACE.

vpMatrix vpMatrix::kron ( const vpMatrix m1,
const vpMatrix m2 
)
static

Compute Kronecker product matrix.

Parameters
m1: vpMatrix;
m2: vpMatrix;
Returns
The kronecker product : $ m1 \otimes m2 $

Definition at line 1487 of file vpMatrix.cpp.

References getCols(), and getRows().

bool vpMatrix::loadMatrix ( const char *  filename,
vpMatrix M,
const bool  binary = false,
char *  Header = NULL 
)
static

Load a matrix to a file.

Parameters
filename: Absolute file name.
M: Matrix to be loaded.
binary: If true the matrix is loaded from a binary file, else from a text file.
Header: Header of the file loaded in this parameter.
Returns
Returns true if no problem happened.

Definition at line 3513 of file vpMatrix.cpp.

References resize().

Referenced by vpDot2::defineDots(), and loadMatrix().

static bool vpMatrix::loadMatrix ( std::string  filename,
vpMatrix M,
const bool  binary = false,
char *  Header = NULL 
)
inlinestatic

Load a matrix to a file.

Parameters
filename: absolute file name
M: matrix to be loaded
binary:If true the matrix is load from a binary file, else from a text file.
Header: Header of the file is load in this parameter
Returns
Returns true if no problem appends.

Definition at line 218 of file vpMatrix.h.

References loadMatrix().

std::ostream & vpMatrix::maplePrint ( std::ostream &  os)

Print using MAPLE matrix input format.

Print using the following way so that this output can be directly copied into MAPLE: ([ [0.939846, 0.0300754, 0.340272, ], [0.0300788, 0.984961, -0.170136, ], [-0.340272, 0.170136, 0.924807, ], ])

Definition at line 2735 of file vpMatrix.cpp.

References getCols(), and getRows().

std::ostream & vpMatrix::matlabPrint ( std::ostream &  os)

Print using matlab syntax, to be put in matlab later.

Print using the following form: [ a,b,c; d,e,f; g,h,i]

Definition at line 2706 of file vpMatrix.cpp.

References getRows().

void vpMatrix::mult2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A * B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator*()

Definition at line 393 of file vpMatrix.cpp.

References colNum, vpMatrixException::incorrectMatrixSizeError, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

Referenced by operator*().

void vpMatrix::multMatrixVector ( const vpMatrix A,
const vpColVector b,
vpColVector c 
)
static

Operation c = A * b (c and b are vectors).

The result is placed in the second parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator*(const vpColVector &b) const

Definition at line 811 of file vpMatrix.cpp.

References colNum, getRows(), vpMatrixException::incorrectMatrixSizeError, vpColVector::resize(), rowNum, rowPtrs, and vpERROR_TRACE.

Referenced by vpRotationMatrix::operator*(), and operator*().

void vpMatrix::negateMatrix ( const vpMatrix A,
vpMatrix C 
)
static

Operation C = -A.

The result is placed in the second parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator-(void)

Definition at line 709 of file vpMatrix.cpp.

References colNum, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

Referenced by operator-().

vpMatrix vpMatrix::operator* ( const vpMatrix B) const

Operation C = A * B (A is unchanged).

See also
mult2Matrices() to avoid matrix allocation for each use.

Definition at line 436 of file vpMatrix.cpp.

References mult2Matrices().

vpColVector vpMatrix::operator* ( const vpColVector b) const

Operation c = A * b (A is unchanged, c and b are vectors).

See also
multMatrixVector() to avoid matrix allocation for each use.

Definition at line 846 of file vpMatrix.cpp.

References multMatrixVector().

vpTranslationVector vpMatrix::operator* ( const vpTranslationVector b) const

Operation c = A * b (A is unchanged, c and b are translation vectors).

Definition at line 855 of file vpMatrix.cpp.

References colNum, vpMatrixException::incorrectMatrixSizeError, rowNum, rowPtrs, and vpERROR_TRACE.

vpMatrix vpMatrix::operator* ( const double  x) const

Cij = Aij * x (A is unchanged)

Definition at line 930 of file vpMatrix.cpp.

References colNum, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

vpMatrix & vpMatrix::operator*= ( const double  x)

Multiply all the element of the matrix by x : Aij = Aij * x.

Definition at line 1058 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

vpMatrix vpMatrix::operator+ ( const vpMatrix B) const

Operation C = A + B (A is unchanged).

See also
add2Matrices() to avoid matrix allocation for each use.

Definition at line 544 of file vpMatrix.cpp.

References add2Matrices().

vpMatrix & vpMatrix::operator+= ( const vpMatrix B)

Operation A = A + B.

Definition at line 624 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, rowNum, rowPtrs, and vpERROR_TRACE.

vpMatrix & vpMatrix::operator+= ( const double  x)

Add x to all the element of the matrix : Aij = Aij + x.

Definition at line 1010 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

vpMatrix vpMatrix::operator- ( const vpMatrix B) const

Operation C = A - B (A is unchanged).

See also
sub2Matrices() to avoid matrix allocation for each use.

Definition at line 615 of file vpMatrix.cpp.

References sub2Matrices().

vpMatrix vpMatrix::operator- ( void  ) const

Operation C = -A (A is unchanged).

See also
negateMatrix() to avoid matrix allocation for each use.

Definition at line 751 of file vpMatrix.cpp.

References negateMatrix().

vpMatrix & vpMatrix::operator-= ( const vpMatrix B)

Operation A = A - B.

Definition at line 664 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, rowNum, rowPtrs, and vpERROR_TRACE.

vpMatrix & vpMatrix::operator-= ( const double  x)

Substract x to all the element of the matrix : Aij = Aij - x.

Definition at line 1034 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

vpMatrix vpMatrix::operator/ ( const double  x) const

Cij = Aij / x (A is unchanged)

Definition at line 965 of file vpMatrix.cpp.

References colNum, vpException::divideByZeroError, resize(), rowNum, rowPtrs, vpCERROR, and vpERROR_TRACE.

vpMatrix & vpMatrix::operator/= ( double  x)

Divide all the element of the matrix by x : Aij = Aij / x.

Definition at line 1073 of file vpMatrix.cpp.

References colNum, vpException::divideByZeroError, rowNum, and rowPtrs.

vpMatrix & vpMatrix::operator<< ( double *  x)

Assigment from an array of double.

Definition at line 368 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

vpMatrix & vpMatrix::operator= ( const vpMatrix B)

Copy operator. Allow operation such as A = B.

Parameters
B: matrix to be copied.

Definition at line 316 of file vpMatrix.cpp.

References colNum, data, dsize, resize(), rowNum, and vpERROR_TRACE.

vpMatrix & vpMatrix::operator= ( const double  x)

Set all the element of the matrix A to x.

set all the element of the matrix A to x

Definition at line 337 of file vpMatrix.cpp.

References colNum, rowNum, and rowPtrs.

double* vpMatrix::operator[] ( unsigned int  n)
inline

write elements Aij (usage : A[i][j] = x )

Definition at line 248 of file vpMatrix.h.

double* vpMatrix::operator[] ( unsigned int  n) const
inline

read elements Aij (usage : x = A[i][j] )

Definition at line 250 of file vpMatrix.h.

int vpMatrix::print ( std::ostream &  s,
unsigned int  length,
char const *  intro = 0 
)

Pretty print a matrix. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter maxlen.

Parameters
sStream used for the printing.
lengthThe suggested width of each matrix element. The actual width grows in order to accomodate the whole integral part, and shrinks if the whole extent is not needed for all the numbers.
introThe introduction which is printed before the matrix. Can be set to zero (or omitted), in which case the introduction is not printed.
Returns
Returns the common total width for all matrix elements
See also
std::ostream &operator <<(ostream &s,const vpMatrix &m)
Examples:
servoSimu3D_cdMc_CamVelocity.cpp, servoSimu3D_cMcd_CamVelocity.cpp, testMatrix.cpp, and testTwistMatrix.cpp.

Definition at line 2615 of file vpMatrix.cpp.

References getCols(), getRows(), and vpMath::maximum().

void vpMatrix::printSize ( )
inline

Definition at line 183 of file vpMatrix.h.

vpMatrix vpMatrix::pseudoInverse ( double  svThreshold = 1e-6) const

Compute the pseudo inverse of the matrix using the SVD.

Compute and return the pseudo inverse of a n-by-m matrix : $ A^+ $.

Parameters
svThreshold: Threshold used to test the singular values.
Returns
Pseudo inverse of the matrix.

Here an example to compute the inverse of a n-by-n matrix. If the matrix is n-by-n it is also possible to use inverseByLU().

#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(4,4);
A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.;
A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.;
A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.;
A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.;
// Compute the inverse
vpMatrix A_1; // A^-1
A_1 = A.pseudoInverse();
std::cout << "Inverse by pseudo inverse: \n" << A_1 << std::endl;
std::cout << "A*A^-1: \n" << A * A_1 << std::endl;
}
See also
inverseByLU()

Definition at line 1812 of file vpMatrix.cpp.

Referenced by vpCalibration::calibrationTsai(), vpSimulatorAfma6::computeArticularVelocity(), vpSimulatorViper850::computeArticularVelocity(), vpServo::computeControlLaw(), computeCovarianceMatrix(), vpHomography::computeDisplacement(), vpHomography::computeRotation(), vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), vpMbEdgeTracker::computeVVS(), vpNurbs::globalCurveApprox(), vpNurbs::globalCurveInterp(), vpHomography::HartleyDenormalization(), vpMeEllipse::initTracking(), vpHomography::inverse(), vpMeLine::leastSquare(), vpPose::poseDementhonNonPlan(), vpPose::poseFromRectangle(), vpPose::poseVirtualVS(), pseudoInverse(), and solveBySVD().

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
double  svThreshold = 1e-6 
) const

Compute the pseudo inverse of the matrix $Ap = A^+$.

Compute the pseudo inverse of the matrix using the SVD. return the rank

Parameters
Ap: The pseudo inverse $ A^+ $.
svThreshold: Threshold used to test the singular values.
Returns
Return the rank of the matrix A

Definition at line 1772 of file vpMatrix.cpp.

References pseudoInverse().

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold = 1e-6 
) const

Compute the pseudo inverse of the matrix $Ap = A^+$.

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
Returns
Return the rank of the matrix A

Definition at line 1828 of file vpMatrix.cpp.

References pseudoInverse().

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt 
) const

Compute the pseudo inverse of the matrix $Ap = A^+$ along with Ker A, Ker $A^T$, Im A and Im $A^T$.

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value, image

Pseudo inverse, kernel and image are computed using the SVD decomposition.

A is an m x n matrix, if m >=n the svd works on A other wise it works on $A^T$.

Therefore if m>=n we have

\[ {\bf A}_{m\times n} = {\bf U}_{m\times m} {\bf S}_{m\times n} {\bf V^\top}_{n\times n} \]

\[ {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} {\bf A} & | & \mbox{Ker} {\bf A^\top} \end{array} \right] {\bf S} \left[ \begin{array}{c} (\mbox{Im} {\bf A^\top})^\top \\ (\mbox{Ker}{\bf A})^\top \end{array}\right] \]

where Im(A) is an m x r matrix (r is the rank of A) and Im(A^T) is an r x n matrix

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
imAt: Image A^T
imAImage A
Returns
Return the rank of the matrix A

Definition at line 1867 of file vpMatrix.cpp.

References getCols(), getRows(), vpColVector::resize(), resize(), svd(), and t().

unsigned int vpMatrix::pseudoInverse ( vpMatrix Ap,
vpColVector sv,
double  svThreshold,
vpMatrix imA,
vpMatrix imAt,
vpMatrix kerA 
) const

Compute the pseudo inverse of the matrix $Ap = A^+$ along with Ker A, Ker $A^T$, Im A and Im $A^T$.

Compute the pseudo inverse of the matrix using the SVD. return the rank and the singular value, image, kernel.

Pseudo inverse, kernel and image are computed using the SVD decomposition.

A is an m x n matrix, if m >=n the svd works on A other wise it works on $A^T$.

Therefore if m>=n we have

\[ {\bf A}_{m\times n} = {\bf U}_{m\times m} {\bf S}_{m\times n} {\bf V^\top}_{n\times n} \]

\[ {\bf A}_{m\times n} = \left[\begin{array}{ccc}\mbox{Im} {\bf A} & | & \mbox{Ker} {\bf A^\top} \end{array} \right] {\bf S} \left[ \begin{array}{c} (\mbox{Im} {\bf A^\top})^\top \\ (\mbox{Ker}{\bf A})^\top \end{array}\right] \]

where Im(A) is an m x r matrix (r is the rank of A) and Im(A^T) is an r x n matrix

Parameters
Ap: The pseudo inverse $ A^+ $.
sv: Singular values.
svThreshold: Threshold used to test the singular values.
imAImage A
imAt: Image A^T
kerA: null space of A
Returns
Return the rank of the matrix A

Definition at line 2045 of file vpMatrix.cpp.

References getCols(), getRows(), vpColVector::resize(), resize(), row(), sumSquare(), svd(), and t().

void vpMatrix::resize ( const unsigned int  nrows,
const unsigned int  ncols,
const bool  flagNullify = true 
)

Set the size of the matrix and initialize all the values to zero.

Parameters
nrows: number of rows
ncols: number of column
flagNullify: if true, then the matrix is re-initialized to 0 after resize. If false, the initial values from the common part of the matrix (common part between old and new version of the matrix) are kept. Default value is true.
Returns
OK or MEMORY_FAULT if memory cannot be allocated
Examples:
testMatrix.cpp, testMatrixInverse.cpp, and testSvd.cpp.

Definition at line 174 of file vpMatrix.cpp.

References colNum, data, dsize, vpException::memoryAllocationError, rowNum, rowPtrs, t(), trsize, vpCDEBUG, vpDEBUG_TRACE, and vpERROR_TRACE.

Referenced by AAt(), add2Matrices(), add2WeightedMatrices(), AtA(), vpServo::computeControlLaw(), vpMbTracker::computeJTR(), vpMbEdgeKltTracker::computeVVS(), vpMbKltTracker::computeVVS(), createDiagonalMatrix(), diag(), vpProjectionDisplay::display(), vpHomography::DLT(), eigenValues(), eye(), vpPtu46::get_eJe(), vpAfma4::get_eJe(), vpAfma6::get_eJe(), vpBiclops::get_eJe(), vpPtu46::get_fJe(), vpAfma4::get_fJe(), vpAfma6::get_fJe(), vpBiclops::get_fJe(), vpAfma4::get_fJe_inverse(), vpViper::get_fJw(), vpCameraParameters::get_K(), vpCameraParameters::get_K_inverse(), vpRotationMatrix::init(), vpProjectionDisplay::init(), vpVelocityTwistMatrix::init(), vpForceTwistMatrix::init(), vpKalmanFilter::init(), vpHomogeneousMatrix::init(), init(), vpMbtDistanceCylinder::initInteractionMatrixError(), insert(), vpFeatureEllipse::interaction(), vpFeatureVanishingPoint::interaction(), vpFeatureLuminance::interaction(), vpFeatureSegment::interaction(), vpGenericFeature::interaction(), vpFeatureDepth::interaction(), vpFeaturePoint::interaction(), vpFeatureLine::interaction(), vpFeaturePoint3D::interaction(), vpFeaturePointPolar::interaction(), vpFeatureThetaU::interaction(), vpFeatureTranslation::interaction(), juxtaposeMatrices(), kernel(), loadMatrix(), mult2Matrices(), negateMatrix(), operator*(), operator/(), operator=(), vpPose::poseDementhonNonPlan(), vpPose::poseDementhonPlan(), vpPose::poseVirtualVSrobust(), pseudoInverse(), vpIoTools::readConfigVar(), vpRowVector::reshape(), vpColVector::reshape(), vpRowVector::resize(), vpColVector::resize(), vpServo::secondaryTask(), vpColVector::skew(), skew(), stackMatrices(), sub2Matrices(), svd(), t(), transpose(), and vpMatrix().

vpRowVector vpMatrix::row ( const unsigned int  j)

Row extraction.

Return the ith rows of the matrix.

Warning
notice row(1) is the 0th row.

Definition at line 2225 of file vpMatrix.cpp.

References getCols().

Referenced by kernel(), pseudoInverse(), and transpose().

bool vpMatrix::saveMatrix ( const char *  filename,
const vpMatrix M,
const bool  binary = false,
const char *  Header = "" 
)
static

Save a matrix to a file.

Parameters
filename: Absolute file name.
M: Matrix to be saved.
binary: If true the matrix is saved in a binary file, else a text file.
Header: Optional line that will be saved at the beginning of the file.
Returns
Returns true if no problem happened.

Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.

Definition at line 3440 of file vpMatrix.cpp.

References getCols(), and getRows().

Referenced by vpDot2::defineDots(), and saveMatrix().

static bool vpMatrix::saveMatrix ( std::string  filename,
const vpMatrix M,
const bool  binary = false,
const char *  Header = "" 
)
inlinestatic

Save a matrix to a file.

Parameters
filename: absolute file name
M: matrix to be saved
binary:If true the matrix is save in a binary file, else a text file.
Header: optional line that will be saved at the beginning of the file
Returns
Returns true if no problem appends.

Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.

Definition at line 201 of file vpMatrix.h.

References saveMatrix().

void vpMatrix::setIdentity ( const double &  val = 1.0)
void vpMatrix::solveBySVD ( const vpColVector b,
vpColVector x 
) const

Solve a linear system $ A X = B $ using Singular Value Decomposition (SVD).

Non destructive wrt. A and B.

Parameters
b: Vector $ B $.
x: Vector $ X $.

Here an example:

#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
A.solveBySVD(B, X);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
solveBySVD(const vpColVector &)

Definition at line 1573 of file vpMatrix.cpp.

References pseudoInverse().

Referenced by solveBySVD().

vpColVector vpMatrix::solveBySVD ( const vpColVector B) const

Solve a linear system $ A X = B $ using Singular Value Decomposition (SVD).

Non destructive wrt. A and B.

Parameters
B: Vector $ B $.
Returns
Vector $ X $.

Here an example:

#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix A(3,3);
A[0][0] = 4.64;
A[0][1] = 0.288;
A[0][2] = -0.384;
A[1][0] = 0.288;
A[1][1] = 7.3296;
A[1][2] = 2.2272;
A[2][0] = -0.384;
A[2][1] = 2.2272;
A[2][2] = 6.0304;
vpColVector X(3), B(3);
B[0] = 1;
B[1] = 2;
B[2] = 3;
X = A.solveBySVD(B);
// Obtained values of X
// X[0] = 0.2468;
// X[1] = 0.120782;
// X[2] = 0.468587;
std::cout << "X:\n" << X << std::endl;
}
See also
solveBySVD(const vpColVector &, vpColVector &)

Definition at line 1628 of file vpMatrix.cpp.

References colNum, and solveBySVD().

void vpMatrix::stackColumns ( vpColVector out)

Stacks columns of a matrix in a vector.

Parameters
out: a vpColVector.

Definition at line 1373 of file vpMatrix.cpp.

References colNum, data, vpColVector::resize(), rowNum, rowPtrs, vpCERROR, and vpERROR_TRACE.

vpColVector vpMatrix::stackColumns ( )

Stacks columns of a matrix in a vector.

Returns
a vpColVector.

Definition at line 1397 of file vpMatrix.cpp.

References colNum, and rowNum.

void stackMatrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Stack two Matrices C = [ A B ]^T.

stackMatrices. "stack" two matrices C = [ A B ]^T

$ C = \left( \begin{array}{c} A \\ B \end{array}\right) $

Parameters
A: Upper matrix.
B: Lower matrix.
C: Stacked matrix C = [ A B ]^T
Warning
A and B must have the same number of column

Definition at line 2292 of file vpMatrix.cpp.

References getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), vpCERROR, and vpERROR_TRACE.

void vpMatrix::stackMatrices ( const vpMatrix A)

Stack A at the end of the current matrix, or copy if the matrix has no dimensions : this = [ this A ]^T

Here an example for a robot velocity log :

vpMatrix Velocities;
for(unsigned int i = 0;i<100;i++)
{
robot.getVelocity(vpRobot::ARTICULAR_FRAME, v);
Velocities.stackMatrices(v.t());
}

Definition at line 2920 of file vpMatrix.cpp.

References rowNum, and stackMatrices().

void vpMatrix::stackRows ( vpRowVector out)

Stacks rows of a matrix in a vector

Parameters
out: a vpRowVector.

Definition at line 1408 of file vpMatrix.cpp.

References colNum, data, dsize, vpRowVector::resize(), rowNum, vpCERROR, and vpERROR_TRACE.

vpRowVector vpMatrix::stackRows ( )

Stacks rows of a matrix in a vector.

Returns
a vpRowVector.

Definition at line 1430 of file vpMatrix.cpp.

References colNum, and rowNum.

void vpMatrix::sub2Matrices ( const vpMatrix A,
const vpMatrix B,
vpMatrix C 
)
static

Operation C = A - B.

The result is placed in the third parameter C and not returned. A new matrix won't be allocated for every use of the function (Speed gain if used many times with the same result matrix size).

See also
operator-()

Definition at line 562 of file vpMatrix.cpp.

References colNum, getCols(), getRows(), vpMatrixException::incorrectMatrixSizeError, resize(), rowNum, rowPtrs, and vpERROR_TRACE.

Referenced by operator-().

void vpMatrix::svd ( vpColVector w,
vpMatrix v 
)

Singular value decomposition (SVD).

\[ M = U \Sigma V^{\top} \]

Warning
Destructive method wrt. to the matrix $ M $ to decompose. You should make a COPY of that matrix if needed not to CHANGE.
Parameters
w: Vector of singular values. $ \Sigma = diag(w) $.
v: Matrix $ V $.
Returns
Matrix $ U $.
Warning
If the GNU Scientific Library (GSL) third party library is used to compute the SVD decomposition, the singular values $ \Sigma_{i,i} $ are ordered in decreasing fashion in w. This is not the case, if the GSL is not detected by ViSP.

Here an example of SVD decomposition of a non square Matrix M.

#include <visp/vpColVector.h>
#include <visp/vpMatrix.h>
int main()
{
vpMatrix M(3,2);
M[0][0] = 1;
M[1][0] = 2;
M[2][0] = 0.5;
M[0][1] = 6;
M[1][1] = 8 ;
M[2][1] = 9 ;
vpMatrix Mrec;
vpMatrix Sigma;
M.svd(w, v);
// Here M is modified and is now equal to U
// Construct the diagonal matrix from the singular values
Sigma.diag(w);
// Reconstruct the initial matrix M using the decomposition
Mrec = M * Sigma * v.t();
// Here, Mrec is obtained equal to the initial value of M
// Mrec[0][0] = 1;
// Mrec[1][0] = 2;
// Mrec[2][0] = 0.5;
// Mrec[0][1] = 6;
// Mrec[1][1] = 8 ;
// Mrec[2][1] = 9 ;
std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl;
}
Examples:
servoMomentImage.cpp.

Definition at line 1702 of file vpMatrix.cpp.

References getCols(), getRows(), vpColVector::resize(), and resize().

Referenced by vpHomography::computeDisplacement(), vpHomography::DLT(), kernel(), vpPose::poseDementhonPlan(), and pseudoInverse().

vpMatrix vpMatrix::transpose ( ) const

Compute and return the transpose of the matrix.

See also
t()

Definition at line 1206 of file vpMatrix.cpp.

void vpMatrix::transpose ( vpMatrix At) const

Compute At the transpose of the matrix.

Parameters
At: Resulting transpose matrix.
See also
t()

Definition at line 1218 of file vpMatrix.cpp.

References colNum, resize(), row(), rowNum, rowPtrs, vpCERROR, and vpERROR_TRACE.

Friends And Related Function Documentation

vpMatrix operator* ( const double &  x,
const vpMatrix B 
)
related

Multiplication by a scalar Cij = x*Bij.

Definition at line 886 of file vpMatrix.cpp.

References getCols(), getRows(), resize(), and vpERROR_TRACE.

VISP_EXPORT std::ostream& operator<< ( std::ostream &  s,
const vpMatrix m 
)
friend

std::cout a matrix

Definition at line 2576 of file vpMatrix.cpp.

void skew ( const vpTranslationVector t,
vpMatrix M 
)
related

Compute the skew symmetric matrix $M$ of translation vector $t$ (matrice de pre-produit vectoriel).

\[ \mbox{if} \quad {\bf t} = \left( \begin{array}{c} t_x \\ t_y \\ t_z \end{array}\right), \quad \mbox{then} \qquad M = \left( \begin{array}{ccc} 0 & -t_z & t_y \\ t_z & 0 & -t_x \\ -t_y & t_x & 0 \end{array}\right) \]

Parameters
t: Translation vector in input used to compute the skew symmetric matrix M.
M: Skew symmetric matrix of translation vector $t$.
Examples:
servoSimuSphere.cpp.

Definition at line 296 of file vpTranslationVector.cpp.

References resize().

void vpGEMM ( const vpMatrix A,
const vpMatrix B,
const double &  alpha,
const vpMatrix C,
const double &  beta,
vpMatrix D,
const unsigned int &  ops = 0 
)
related

This function performs generalized matrix multiplication: D = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T. Operation on A, B and C matrices is described by enumeration vpGEMMmethod.

For example, to compute alpha*A^T*B^T+beta*C we need to call :

vpGEMM(A,B,alpha,C,beta, VP_GEMM_A_T + VP_GEMM_B_T);

If C is not used, vpGEMM must be called using an empty matrix null :

vpGEMM(A,B,alpha,C, null,0);
Exceptions
vpMatrixException::incorrectMatrixSizeErrorif the sizes of the matrices do not allow the operations.
Parameters
A: a Matrix
B: a Matrix
alpha: a scalar
C: a Matrix
beta: a scalar
D: a Matrix
ops: a scalar describing operation applied on the matrices
Examples:
testMatrix.cpp.

Definition at line 331 of file vpGEMM.h.

References vpMatrixException::incorrectMatrixSizeError, and vpERROR_TRACE.

enum vpGEMMmethod
related

Enumeration of the operations applied on matrices in vpGEMM function.

Operations are :

  • VP_GEMM_A_T to use the transpose matrix of A instead of the matrix A
  • VP_GEMM_B_T to use the transpose matrix of B instead of the matrix B
  • VP_GEMM_C_T to use the transpose matrix of C instead of the matrix C

Definition at line 63 of file vpGEMM.h.

Member Data Documentation

double* vpMatrix::data

address of the first element of the data array

Definition at line 116 of file vpMatrix.h.

Referenced by AtA(), vpSubColVector::checkParentStatus(), vpSubRowVector::checkParentStatus(), vpSubMatrix::checkParentStatus(), vpPose::computeResidual(), vpHomography::computeResidual(), vpPose::computeTransformation(), vpHomography::computeTransformation(), vpColVector::dotProd(), eigenValues(), euclideanNorm(), vpRobotViper650::getForceTorque(), vpRobotViper850::getForceTorque(), getMaxValue(), getMinValue(), vpRobotViper650::getPosition(), vpRobotViper850::getPosition(), vpRobotViper850::getVelocity(), vpRobotViper650::getVelocity(), vpSubColVector::init(), vpSubRowVector::init(), vpSubMatrix::init(), init(), vpRobotViper650::init(), vpRobotViper850::init(), inverseByCholeskyLapack(), inverseByQRLapack(), vpColVector::invSort(), kill(), vpColVector::mean(), vpColVector::median(), vpRowVector::operator*(), vpColVector::operator*(), vpTranslationVector::operator*(), vpHomography::operator*(), vpColVector::operator+(), vpTranslationVector::operator-(), vpColVector::operator-(), vpHomography::operator/(), vpSubColVector::operator=(), vpSubRowVector::operator=(), vpRowVector::operator=(), vpColVector::operator=(), vpTranslationVector::operator=(), operator=(), vpRowVector::operator[](), vpColVector::operator[](), vpPose::ransac(), vpHomography::ransac(), vpRowVector::reshape(), vpColVector::reshape(), resize(), vpRobotAfma4::setPosition(), vpRobotViper650::setPosition(), vpRobotViper850::setPosition(), vpRobotAfma4::setVelocity(), vpRobotAfma6::setVelocity(), vpRobotViper650::setVelocity(), vpRobotViper850::setVelocity(), vpColVector::sort(), stackColumns(), stackRows(), vpRowVector::t(), vpColVector::t(), vpColVector::vpColVector(), vpMatrix(), vpSubColVector::vpSubColVector(), vpSubMatrix::vpSubMatrix(), vpSubRowVector::vpSubRowVector(), vpSubColVector::~vpSubColVector(), vpSubMatrix::~vpSubMatrix(), and vpSubRowVector::~vpSubRowVector().

unsigned int vpMatrix::trsize
protected