Matrix Science header
Public Member Functions | Static Public Member Functions

ms_matrix Class Reference
[Mascot utilities and tools module]

A two-dimensional matrix of numbers. More...

#include <ms_matrix.hpp>

List of all members.

Public Member Functions

 ms_matrix ()
 Construct empty matrix.
 ms_matrix (const matrix_t &m)
 Construct a copy of a matrix.
 ms_matrix (size_t si, size_t sj, double v=0.0)
 Construct a rectangular matrix.
const matrix_t & data () const
 Get the internal constant matrix data.
double getCR (size_t i, size_t j) const
 Get the value for the specified row and column.
double getRC (size_t i, size_t j) const
 Get the value for the specified row and column.
bool isZero () const
 Return true if all values are zero.
void logContents (ms_errs &errs, const char *description) const
 Dump the contents of the matrix to the log.
double multiplyByRow (const std::vector< double > &column, size_t row) const
 Multiply the column matrix by the selected row matrix and return the resulting value. The column must be the same size as a row (getNumColumns) in the matrix.
bool operator!= (const ms_matrix &m) const
 Compare two matrices; size and all values.
ms_matrix operator* (const ms_matrix &m) const
 Multiply two matrices to produce a product matrix.
bool operator== (const ms_matrix &m) const
 Compare two matrices.
column_vector_t & operator[] (size_t i)
 Get a single column as a vector.
const column_vector_t & operator[] (size_t i) const
 Get a single column as a constant vector.
void resize (size_t si, size_t sj, double v=0.0)
 Change the size of the matrix, growing or shrinking as required. If grown then the data will be retained.
void setColumnDown (size_t row, size_t col, const std::vector< double > &vec)
 Copies the values in the passed vector into the column specified, starting at the passed row.
void setColumnUp (size_t row, size_t col, const std::vector< double > &vec)
 Copies the values in the passed vector into the column specified, starting at the passed row.
void setCR (size_t i, size_t j, double value)
 Set the value for the specified row and column.
void setRC (size_t i, size_t j, double value)
 Set the value for the specified row and column.
size_t sizei () const
 Return the number of columns in the matrix.
size_t sizej () const
 Return the number of rows in the matrix.
void transpose ()
 Transpose the matrix in place.

Static Public Member Functions

static ms_matrix columnMatrix (const std::vector< double > &v)
 Returns a matrix with a single column.
static ms_matrix diagonalMatrix (size_t s, double v)
 Returns a square, diagonal matrix.
static ms_matrix identityMatrix (size_t s)
 Returns a square, identity matrix.
static ms_matrix rowMatrix (const std::vector< double > &v)
 Returns a matrix with a single row.

Detailed Description

A two-dimensional matrix of numbers.

The size of a matrix is defined by the number of rows and columns that it contains.

The entry in the j-th row and i-th column of a matrix A is accessed as A[i][j]. Note that this is the opposite of the conventional mathematical notation, where the j-th row of the i-th column of a matrix A is referred to as A[j,i].

The row and column indexes are zero-based (0 to n-1). Note that this differs from the conventional mathematical notation where indexes are one-based (1 to n).


Constructor & Destructor Documentation

ms_matrix (  )

Construct empty matrix.

No rows and no columns.

ms_matrix ( const matrix_t &  m )

Construct a copy of a matrix.

Parameters:
mThe matrix to copy.

Member Function Documentation

ms_matrix columnMatrix ( const std::vector< double > &  v ) [static]

Returns a matrix with a single column.

The column size will be the number of values given.

Parameters:
vThe values placed in the column.
Returns:
The column matrix.
const ms_matrix::matrix_t & data (  ) const

Get the internal constant matrix data.

Returns:
The internal representation of the matrix values.
ms_matrix diagonalMatrix ( size_t  s,
double  v 
) [static]

Returns a square, diagonal matrix.

All values are zero except for the diagonal values.

Parameters:
sThe size of a row or column; the number of columns and rows.
vThe value placed in every diagonal entry in the matrix.
Returns:
The diagonal matrix.
double getCR ( size_t  i,
size_t  j 
) const

Get the value for the specified row and column.

Parameters:
iThe number of the column to retrieve from (0 .. m-1).
jThe number of the row to retrieve from (0 .. n-1).
Returns:
The value of the selected entry.
ms_matrix identityMatrix ( size_t  s ) [static]

Returns a square, identity matrix.

All values are zero except for 1.0 in all the diagonal values.

Parameters:
sThe size of a row or column; the number of columns and rows.
Returns:
The identity matrix.
bool isZero (  ) const

Return true if all values are zero.

Returns:
True if all entries are zero. False if any entry is non-zero.
void logContents ( ms_errs errs,
const char *  description 
) const

Dump the contents of the matrix to the log.

Outputs to the log if the logging level is high enough for message: ms_log::LOGMSG_MATRIX_OUTPUT_VALS

Parameters:
errsis the error handler
descriptionshould be used to describe the matrix
bool operator!= ( const ms_matrix m ) const

Compare two matrices; size and all values.

Parameters:
mreference to a valid ms_matrix object
Returns:
True if either size or any entry is not identical.
ms_matrix operator* ( const ms_matrix m ) const

Multiply two matrices to produce a product matrix.

The number of columns in the left-hand matrix must equal the number of rows in the right hand matrix.

The product matrix has a number of rows equal to the number of rows in the left-hand matrix and a number of columns equal to the number of columns in the right-hand matrix.

For example, a 2x3 matrix A can be mutlipled by a 4x2 matrix B, C=A*B, to produce a 4x3 matrix.but not the other way around, C=B*A.) (e.g. a 2x3 matrix multiplied by a 4x2 matrix would have a size of 4x3.)

Parameters:
mreference to a valid ms_matrix object
Returns:
new object of type ms_matrix
bool operator== ( const ms_matrix m ) const

Compare two matrices.

Parameters:
mreference to a valid ms_matrix object
Returns:
True if the size and all entries are identical.
const ms_matrix::column_vector_t & operator[] ( size_t  i ) const

Get a single column as a constant vector.

Parameters:
iThe number of the column to retrieve (0 .. m-1).
Returns:
The selected column.
ms_matrix::column_vector_t & operator[] ( size_t  i )

Get a single column as a vector.

Parameters:
iThe number of the column to retrieve (0 .. m-1).
Returns:
The selected column.
void resize ( size_t  si,
size_t  sj,
double  v = 0.0 
)

Change the size of the matrix, growing or shrinking as required. If grown then the data will be retained.

Parameters:
siThe new number of columns.
sjThe new number of the rows.
vThe value to place in new entries.
ms_matrix rowMatrix ( const std::vector< double > &  v ) [static]

Returns a matrix with a single row.

The row size will be the number of values given.

Parameters:
vThe values placed in the row.
Returns:
The row matrix.
void setColumnDown ( size_t  row,
size_t  col,
const std::vector< double > &  vec 
)

Copies the values in the passed vector into the column specified, starting at the passed row.

The first value in vec is copied into row, col
The second value in vec is copied into row+1, col
etc.

If vec is larger than the size of the matrix, then the copying stops at the final row in the matrix.

Parameters:
rowis the zero based row to start copying
colis the column to be filled with values
veccontains the values to be copied
void setColumnUp ( size_t  row,
size_t  col,
const std::vector< double > &  vec 
)

Copies the values in the passed vector into the column specified, starting at the passed row.

The last value in vec is copied into row, col
The second last value in vec is copied into row-1, col
etc.

If vec is larger than the size of the matrix, then the copying stops at the first row in the matrix.

Parameters:
rowis the zero based row to start copying
colis the column to be filled with values
veccontains the values to be copied
void setCR ( size_t  i,
size_t  j,
double  value 
)

Set the value for the specified row and column.

Parameters:
iThe number of the column to retrieve from (0 .. m-1).
jThe number of the row to retrieve from (0 .. n-1).
valueThe number to be stored in the specified matrix element.
size_t sizei (  ) const

Return the number of columns in the matrix.

Returns:
The size of a row.
size_t sizej (  ) const

Return the number of rows in the matrix.

Returns:
The size of a column.
void transpose (  )

Transpose the matrix in place.

Reflects the matrix over its main diagonal (which runs from top-left to bottom-right) to obtain its inverse.


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

Copyright © 2022 Matrix Science Ltd.  All Rights Reserved. Generated on Thu Mar 31 2022 01:12:34