51 Matrix(
const int& rows,
const int& cols);
60 Matrix(
const size_t& rows,
const size_t& cols,
const double& init) :
vecData(rows*cols, init),
ncols(cols),
nrows(rows) {}
67 Matrix(
const size_t& n,
const double& init);
75 Matrix(
const size_t& rows,
const size_t& cols,
const std::vector<double> data) :
vecData(data),
ncols(cols),
nrows(rows) {}
82 void identity(
const size_t& n,
const double& init = 1.);
84 void resize(
const size_t& rows,
const size_t& cols);
85 void resize(
const size_t& rows,
const size_t& cols,
const double& init);
86 void resize(
const size_t& rows,
const size_t& cols,
const std::vector<double>& data);
93 void size(
size_t& rows,
size_t& cols)
const;
107 void random(
const double& range);
109 double&
operator ()(
const size_t& x,
const size_t& y);
110 double operator ()(
const size_t& x,
const size_t& y)
const;
190 Matrix extract(
size_t r_low,
size_t r_high,
size_t c_low,
size_t c_high)
const;
198 double maxCoeff(
size_t& max_row,
size_t& max_col)
const;
371 void swapCols(
const size_t &j1,
const size_t &j2);
373 const std::string
toString(
const int& precision=2,
const bool& prettify=
true)
const;
412 void swapRows(
const size_t &i1,
const size_t &i2);
This class implements the basic operations on matrices. Elements are access in matrix notation: that ...
Definition: Matrix.h:42
const Matrix operator+(const Matrix &rhs) const
Definition: Matrix.cc:213
static Matrix TDMA_solve(const Matrix &A, const Matrix &B)
Solving system of equations using Thomas Algorithm The following function solves a A·X=B with X and B...
Definition: Matrix.cc:803
Matrix getDiagonal() const
Copy the matrix diagonal to a new 1-column-matrix.
Definition: Matrix.cc:649
static double dot(const Matrix &A, const Matrix &B)
Dot product.
Definition: Matrix.cc:362
bool operator!=(const Matrix &) const
Operator that tests for inequality.
Definition: Matrix.cc:190
static bool gaussSolve(Matrix &M, Matrix &A, Matrix &X)
Equation system solver via Gaussian elimination. This function solves a set of equations M·X=A via Ga...
Definition: Matrix.cc:841
Matrix(const size_t &rows, const size_t &cols, const double &init)
A constructor that creates a matrix filled with constant values.
Definition: Matrix.h:60
bool LU(Matrix &L, Matrix &U) const
matrix LU decomposition. Perform LU decomposition by the Dolittle algorithm, (cf http://math....
Definition: Matrix.cc:430
Matrix()
Definition: Matrix.h:44
static void gaussElimination(Matrix &M, std::vector< size_t > &p)
Gaussian elimimination with partial pivoting. This function performs row reduction with (virtual) row...
Definition: Matrix.cc:813
double scalar() const
Converts a 1x1 matrix to a scalar.
Definition: Matrix.cc:351
bool operator==(const Matrix &) const
Operator that tests for equality.
Definition: Matrix.cc:176
Matrix getCol(const size_t j) const
Copy a matrix column to a new 1-column-matrix.
Definition: Matrix.cc:614
static Matrix solve(const Matrix &A, const Matrix &B)
matrix solving for A·X=B. It first performs LU decomposition and then solves A·X=B by backward and fo...
Definition: Matrix.cc:745
Matrix & operator+=(const Matrix &rhs)
Definition: Matrix.cc:195
std::vector< double > vecData
Definition: Matrix.h:406
void setCol(const size_t j, const Matrix &col)
Set a matrix column from a 1-column-matrix.
Definition: Matrix.cc:630
bool inv()
Definition: Matrix.cc:524
double & operator()(const size_t &x, const size_t &y)
Definition: Matrix.cc:122
void clear()
free the memory and set the matrix dimensions to (0,0)
Definition: Matrix.cc:108
void T()
Definition: Matrix.cc:407
size_t getNy() const
Definition: Matrix.h:96
static double jacobiEpsilon(Matrix &AA)
Definition: Matrix.cc:1148
void resize(const size_t &rows, const size_t &cols)
Definition: Matrix.cc:71
const Matrix operator/(const double &rhs) const
Definition: Matrix.cc:338
const Matrix operator*(const Matrix &rhs) const
Definition: Matrix.cc:308
size_t ncols
Definition: Matrix.h:407
Matrix & operator*=(const Matrix &rhs)
Definition: Matrix.cc:279
static void svdJacobi(const Matrix &MM, Matrix &UU, Matrix &SS, Matrix &VV)
Singular Value Decomposition. This function calculates the SVD of a matrix. It uses an eigenvector se...
Definition: Matrix.cc:1161
Matrix getInv() const
matrix invert. It first performs LU decomposition (Dolittle algorithm) and then computes the inverse ...
Definition: Matrix.cc:468
static const double epsilon
Definition: Matrix.h:403
Matrix getRow(const size_t i) const
Copy a matrix row to a new 1-row-matrix.
Definition: Matrix.cc:579
Matrix & operator-=(const Matrix &rhs)
Definition: Matrix.cc:238
Matrix(const size_t &rows, const size_t &cols, const std::vector< double > data)
A constructor that takes a data vector to fill the matrix.
Definition: Matrix.h:75
Matrix(const size_t &rows, const size_t &cols)
Definition: Matrix.h:52
void maximalPivoting()
Definition: Matrix.cc:997
static const double epsilon_mtr
Definition: Matrix.h:403
double det() const
matrix determinant
Definition: Matrix.cc:413
static double normEuclid(const Matrix &vv)
Calculate Euclidean norm (l2) for a vector. The matrix must either be a row or a column vector.
Definition: Matrix.cc:922
bool isIdentity() const
check if a matrix is the identity matrix
Definition: Matrix.cc:938
static void sortEigenvalues(Matrix &EE, Matrix &VV)
Definition: Matrix.cc:1181
void random(const double &range)
fill the matrix with random numbers.
Definition: Matrix.cc:114
double maxCoeff(size_t &max_row, size_t &max_col) const
Find the first maximum value in the matrix.
Definition: Matrix.cc:1057
static bool gaussInverse(Matrix &M)
Matrix inversion via Gaussian elimination. Attention: The original matrix is destroyed!
Definition: Matrix.cc:885
size_t findMaxInRow(const size_t &row)
Definition: Matrix.cc:1042
void size(size_t &rows, size_t &cols) const
get the dimensions of the current object
Definition: Matrix.cc:102
void swapCols(const size_t &j1, const size_t &j2)
Definition: Matrix.cc:1082
void partialPivoting()
Definition: Matrix.cc:991
static double gaussDet(Matrix &M)
Get the matrix determinant via Gaussian elimination. Attention: The original matrix is destroyed!
Definition: Matrix.cc:903
size_t findMaxInCol(const size_t &col)
Definition: Matrix.cc:1026
size_t getNx() const
Definition: Matrix.h:95
Matrix extract(size_t r_low, size_t r_high, size_t c_low, size_t c_high) const
Extract a submatrix to a new matrix. IOUtils::npos for an index means "from beginning" (i....
Definition: Matrix.cc:665
Matrix & operator/=(const double &rhs)
Definition: Matrix.cc:332
static unsigned int eigenvaluesJacobi(Matrix &AA, Matrix &DD)
matrix bidiagonalization This uses Householder's reduction, see Golub, 1970. (see https://secure....
Definition: Matrix.cc:1091
Matrix getT() const
matrix transpose.
Definition: Matrix.cc:396
void setRow(const size_t i, const Matrix &row)
Set a matrix row from a 1-row-matrix.
Definition: Matrix.cc:595
const Matrix operator-(const Matrix &rhs) const
Definition: Matrix.cc:256
size_t nrows
Definition: Matrix.h:408
void swapRows(const size_t &i1, const size_t &i2)
Definition: Matrix.cc:1073
void identity(const size_t &n, const double &init=1.)
Convert the current matrix to a identity matrix of size n.
Definition: Matrix.cc:65
const std::string toString(const int &precision=2, const bool &prettify=true) const
Definition: Matrix.cc:146