PARTONS/NumA++  
Numerical Analysis C++ routines
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
NumA::MatrixD Class Reference

Represents a two-dimensional array of double. More...

Public Member Functions

 MatrixD ()
 Default constructor. More...
 
 MatrixD (const size_t _rowsNumber, const size_t _columnsNumber, double first_value,...)
 Creates a matrix with specific dimensions and fills it with given values separated by comma. More...
 
 MatrixD (const size_t _rowsNumber, const size_t _columnsNumber)
 Creates matrix with specific dimensions and fills it with 0. More...
 
 MatrixD (const MatrixD &rhs)
 Copy constructor. More...
 
 MatrixD (const VectorD &rhs)
 VectorD constructor (creates a one-column matrix). More...
 
virtual ~MatrixD ()
 Default destructor. More...
 
void assign (const size_t _rowsNumber, const size_t _columnsNumber, double value=0.)
 Assigns a new matrix with all coefficients set to value. More...
 
void setLine (size_t i, const NumA::VectorD &line)
 Sets an existing line of the matrix to new values given by a vector. More...
 
void addLine (size_t i, const NumA::VectorD &line)
 Adds a new line in the matrix (its dimension is therefore incremented) with the values given by a vector. More...
 
void appendLine (const NumA::VectorD &line)
 Adds a new line at the end of the matrix (its dimension is therefore incremented) with the values given by a vector. More...
 
NumA::VectorD getLine (const size_t lineIndex) const
 Extracts a single line from the matrix. More...
 
NumA::VectorD operator* (const NumA::VectorD &rhs) const
 Matrix vector multiplication. More...
 
NumA::MatrixD operator* (const NumA::MatrixD &rhs) const
 Matrix-matrix multiplication. More...
 
NumA::MatrixD operator+ (const NumA::MatrixD &rhs) const
 Matrix addition. More...
 
NumA::MatrixD operator- (const NumA::MatrixD &rhs) const
 Matrix subtraction. More...
 
NumA::MatrixD operator* (double rhs) const
 Multiplication of all the coefficients by a scalar. More...
 
NumA::MatrixD operator+ (double rhs) const
 Addition coefficient by coefficient with a scalar. More...
 
NumA::MatrixD operator- (double rhs) const
 Subtraction coefficient by coefficient with a scalar. More...
 
NumA::MatrixD operator/ (double rhs) const
 Division of all the coefficients by a scalar. More...
 
NumA::MatrixD transpose () const
 Matrix transpose. More...
 
void update (const size_t i, const size_t j, const double value)
 Update the value at the given indices. More...
 
double & at (const size_t i, const size_t j)
 Element access. More...
 
const double & at (const size_t i, const size_t j) const
 Element access. More...
 
std::string toString () const
 Return a formatted characters string to display matrix's values. More...
 
size_t cols () const
 
size_t rows () const
 

Static Public Member Functions

static NumA::MatrixD Id (unsigned int n)
 Matrix identity. More...
 

Private Attributes

std::vector< double > m_matrix
 A flat std::vector to represent the matrix. More...
 
size_t m_rowsNumber
 Number of rows. More...
 
size_t m_columnsNumber
 Number of columns. More...
 

Detailed Description

Represents a two-dimensional array of double.

The indices start at 0 up to size-1.

Examples:

NumA::MatrixD A(5,5); // 5x5 matrix with coefficients equal to 0.
A.at(1,3) = 10.; // Defines one coefficient (second row, fourth column).
NumA::MatrixD B = NumA::MatrixD::Id(5); // Identity matrix.
B.at(4,4) = 5.; // Last row, last column.
// Matrix operations:
C = A*B + B/2.;
Represents a two-dimensional array of double.
Definition: MatrixD.h:49
static NumA::MatrixD Id(unsigned int n)
Matrix identity.
Definition: MatrixD.cpp:207
std::string toString() const
Return a formatted characters string to display matrix's values.
Definition: MatrixD.cpp:226
double & at(const size_t i, const size_t j)
Element access.
Definition: MatrixD.cpp:316

This returns:

0.5 0 0 0 0
0 0.5 0 10 0
0 0 0.5 0 0
0 0 0 0.5 0
0 0 0 0 2.5

Constructor & Destructor Documentation

◆ MatrixD() [1/5]

NumA::MatrixD::MatrixD ( )

Default constructor.


Initializes an empty matrix.

◆ MatrixD() [2/5]

NumA::MatrixD::MatrixD ( const size_t  _rowsNumber,
const size_t  _columnsNumber,
double  first_value,
  ... 
)

Creates a matrix with specific dimensions and fills it with given values separated by comma.

TODO: Write something better?

If the number and type of arguments are not right, UNDEFINED BEHAVIOUR !!! This constructor is very DANGEROUS!!! USE IT RIGHT, OR SCRAP IT ALL AND REWRITE SOMETHING BETTER!

Parameters
_rowsNumber: number of rows
_columnsNumber: number of columns
first_value: first value of the matrix

◆ MatrixD() [3/5]

NumA::MatrixD::MatrixD ( const size_t  _rowsNumber,
const size_t  _columnsNumber 
)

Creates matrix with specific dimensions and fills it with 0.

Parameters
_rowsNumber: number of rows
_columnsNumber: number of columns

◆ MatrixD() [4/5]

NumA::MatrixD::MatrixD ( const MatrixD rhs)

Copy constructor.

Parameters
rhsMatrix to be copied.

◆ MatrixD() [5/5]

NumA::MatrixD::MatrixD ( const VectorD rhs)

VectorD constructor (creates a one-column matrix).

Parameters
rhsVector to be converted to a matrix.

◆ ~MatrixD()

NumA::MatrixD::~MatrixD ( )
virtual

Default destructor.

Member Function Documentation

◆ addLine()

void NumA::MatrixD::addLine ( size_t  i,
const NumA::VectorD line 
)

Adds a new line in the matrix (its dimension is therefore incremented) with the values given by a vector.

Parameters
iIndex the row where the line will be inserted.
lineVector to copy in the matrix.

◆ appendLine()

void NumA::MatrixD::appendLine ( const NumA::VectorD line)

Adds a new line at the end of the matrix (its dimension is therefore incremented) with the values given by a vector.

Parameters
lineVector to copy in the matrix.

◆ assign()

void NumA::MatrixD::assign ( const size_t  _rowsNumber,
const size_t  _columnsNumber,
double  value = 0. 
)

Assigns a new matrix with all coefficients set to value.

Parameters
_rowsNumberNumber of rows.
_columnsNumberNumber of columns.
valueDefault value for all the coefficients.

◆ at() [1/2]

double & NumA::MatrixD::at ( const size_t  i,
const size_t  j 
)

Element access.

Can be used to set the value of a coefficient.

Parameters
iRow index.
jColumn index.
Returns
Reference to a certain coefficient of the matrix.

◆ at() [2/2]

const double & NumA::MatrixD::at ( const size_t  i,
const size_t  j 
) const

Element access.

Parameters
iRow index.
jColumn index.
Returns
Constant reference to a certain coefficient of the matrix.

◆ cols()

size_t NumA::MatrixD::cols ( ) const
Returns
Number of columns.

◆ getLine()

NumA::VectorD NumA::MatrixD::getLine ( const size_t  lineIndex) const

Extracts a single line from the matrix.

Parameters
lineIndexIndex of the row to be extracted.
Returns
Vector corresponding to the row.

◆ Id()

NumA::MatrixD NumA::MatrixD::Id ( unsigned int  n)
static

Matrix identity.

Parameters
nDimension.
Returns
Matrix identity.

◆ operator*() [1/3]

NumA::MatrixD NumA::MatrixD::operator* ( const NumA::MatrixD rhs) const

Matrix-matrix multiplication.

Parameters
rhsMatrix.
Returns
Product of matrices.

◆ operator*() [2/3]

NumA::VectorD NumA::MatrixD::operator* ( const NumA::VectorD rhs) const

Matrix vector multiplication.

Parameters
rhsVector.
Returns
Vector \( M \cdot V \).

◆ operator*() [3/3]

NumA::MatrixD NumA::MatrixD::operator* ( double  rhs) const

Multiplication of all the coefficients by a scalar.

Parameters
rhsScalar.
Returns
Matrix.

◆ operator+() [1/2]

NumA::MatrixD NumA::MatrixD::operator+ ( const NumA::MatrixD rhs) const

Matrix addition.

Parameters
rhsMatrix.
Returns
Sum of matrices.

◆ operator+() [2/2]

NumA::MatrixD NumA::MatrixD::operator+ ( double  rhs) const

Addition coefficient by coefficient with a scalar.

Parameters
rhsScalar.
Returns
Matrix.

◆ operator-() [1/2]

NumA::MatrixD NumA::MatrixD::operator- ( const NumA::MatrixD rhs) const

Matrix subtraction.

Parameters
rhsMatrix.
Returns
Difference of matrices.

◆ operator-() [2/2]

NumA::MatrixD NumA::MatrixD::operator- ( double  rhs) const

Subtraction coefficient by coefficient with a scalar.

Parameters
rhsScalar.
Returns
Matrix.

◆ operator/()

NumA::MatrixD NumA::MatrixD::operator/ ( double  rhs) const

Division of all the coefficients by a scalar.

Parameters
rhsScalar.
Returns
Matrix.

◆ rows()

size_t NumA::MatrixD::rows ( ) const
Returns
Number of rows.

◆ setLine()

void NumA::MatrixD::setLine ( size_t  i,
const NumA::VectorD line 
)

Sets an existing line of the matrix to new values given by a vector.

Parameters
iIndex of the line to be modified.
lineVector to copy in the matrix.

◆ toString()

std::string NumA::MatrixD::toString ( ) const

Return a formatted characters string to display matrix's values.

Returns
std::string

◆ transpose()

NumA::MatrixD NumA::MatrixD::transpose ( ) const

Matrix transpose.

Returns
Matrix transposed.

◆ update()

void NumA::MatrixD::update ( const size_t  i,
const size_t  j,
const double  value 
)

Update the value at the given indices.

Parameters
iRow index.
jColumn index.
valueNew value for the coefficient.

Member Data Documentation

◆ m_columnsNumber

size_t NumA::MatrixD::m_columnsNumber
private

Number of columns.

◆ m_matrix

std::vector<double> NumA::MatrixD::m_matrix
private

A flat std::vector to represent the matrix.

◆ m_rowsNumber

size_t NumA::MatrixD::m_rowsNumber
private

Number of rows.


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