![]() |
A two-dimensional matrix of numbers. More...
#include <ms_matrix.hpp>
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. |
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).
ms_matrix | ( | ) |
Construct empty matrix.
No rows and no columns.
ms_matrix | ( | const matrix_t & | m ) |
Construct a copy of a matrix.
m | The matrix to copy. |
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.
v | The values placed in the column. |
const ms_matrix::matrix_t & data | ( | ) | const |
Get the internal constant matrix data.
ms_matrix diagonalMatrix | ( | size_t | s, |
double | v | ||
) | [static] |
Returns a square, diagonal matrix.
All values are zero except for the diagonal values.
s | The size of a row or column; the number of columns and rows. |
v | The value placed in every diagonal entry in the matrix. |
double getCR | ( | size_t | i, |
size_t | j | ||
) | const |
Get the value for the specified row and column.
i | The number of the column to retrieve from (0 .. m-1). |
j | The number of the row to retrieve from (0 .. n-1). |
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.
s | The size of a row or column; the number of columns and rows. |
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.
Outputs to the log if the logging level is high enough for message: ms_log::LOGMSG_MATRIX_OUTPUT_VALS
errs | is the error handler |
description | should be used to describe the matrix |
bool operator!= | ( | const ms_matrix & | m ) | const |
Compare two matrices; size and all values.
m | reference to a valid ms_matrix object |
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.)
m | reference to a valid ms_matrix object |
bool operator== | ( | const ms_matrix & | m ) | const |
Compare two matrices.
m | reference to a valid ms_matrix object |
const ms_matrix::column_vector_t & operator[] | ( | size_t | i ) | const |
Get a single column as a constant vector.
i | The number of the column to retrieve (0 .. m-1). |
ms_matrix::column_vector_t & operator[] | ( | size_t | i ) |
Get a single column as a vector.
i | The number of the column to retrieve (0 .. m-1). |
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.
si | The new number of columns. |
sj | The new number of the rows. |
v | The 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.
v | The values placed in the row. |
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.
row | is the zero based row to start copying |
col | is the column to be filled with values |
vec | contains 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.
row | is the zero based row to start copying |
col | is the column to be filled with values |
vec | contains the values to be copied |
void setCR | ( | size_t | i, |
size_t | j, | ||
double | value | ||
) |
Set the value for the specified row and column.
i | The number of the column to retrieve from (0 .. m-1). |
j | The number of the row to retrieve from (0 .. n-1). |
value | The number to be stored in the specified matrix element. |
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.
Reflects the matrix over its main diagonal (which runs from top-left to bottom-right) to obtain its inverse.
Copyright © 2022 Matrix Science Ltd. All Rights Reserved. Generated on Thu Mar 31 2022 01:12:34 |