The HepMatrix class does all the obvious things,
in all the obvious ways.
Authors
Nobu Katayama and Mike Smyth
See also
HepGenMatrix,
HepSymMatrix,
HepDiagMatrix,
HepVector,
HepPile,
Declaration
#include "CLHEP/Matrix/Matrix.h"
class HepMatrix : public HepGenMatrix
Public Member Classes
- HepMatrix_row
- Helper class to implement m[i][j]
- Declaration
- class HepMatrix_row
- Constructor
- inline HepMatrix_row(HepMatrix&, int)
- []
- HepDouble & operator[](int)
- HepMatrix_row_const
- Helper class to implement m[i][j]
- Declaration
- class HepMatrix_row_const
- Constructor
- inline HepMatrix_row_const(const HepMatrix&, int)
- []
- const HepDouble & operator[](int) const
Public Member Functions
- Constructor
- inline HepMatrix()
- Default constructor. Gives 0 x 0 matrix. Another Matrix can be
assigned to it.
- Constructor
- HepMatrix(int p, int q)
- Gives an unitialized p x q matrix.
- Constructor
- HepMatrix(int p, int q, int i)
- Gives an initialized p x q matrix.
If i=0, it is initialized to all 0.
If i=1, the diagonal elements are set to 1.
- Constructor
- #ifdef HEP_USE_RANDOM
- HepMatrix(int p, int q, HepRandom &r)
- #endif
- Constructor with a Random object.
- Constructor
- HepMatrix(const HepSymMatrix &m1)
- Constructor from HepSymMatrix.
- Constructor
- HepMatrix(const HepDiagMatrix &m1)
- Constructor from HepDiagMatrix.
- Constructor
- HepMatrix(const HepVector &m1)
- Constructor from HepVector.
- Copy constructor
- HepMatrix(const HepMatrix &m1)
- Destructor
- virtual ~HepMatrix()
- =
- HepMatrix & operator = (const HepMatrix &m2)
- HepMatrix & operator = (const HepSymMatrix &m2)
- HepMatrix & operator = (const HepDiagMatrix &m2)
- HepMatrix & operator = (const HepVector &m2)
- HepMatrix & operator = (const HepRotation &m2)
- Assignment operators.
- +=
- HepMatrix & operator += (const HepMatrix &m2)
- HepMatrix & operator += (const HepSymMatrix &m2)
- HepMatrix & operator += (const HepDiagMatrix &m2)
- HepMatrix & operator += (const HepVector &m2)
- Add a Matrix.
When adding Vector, Matrix must have num_col of one.
- -
- HepMatrix operator - () const
- Unary minus, i.e. flip the sign of each element.
- -=
- HepMatrix & operator -= (const HepMatrix &m2)
- HepMatrix & operator -= (const HepSymMatrix &m2)
- HepMatrix & operator -= (const HepDiagMatrix &m2)
- HepMatrix & operator -= (const HepVector &m2)
- Subtract a Matrix.
When subtracting Vector, Matrix must have num_col of one.
- *=
- HepMatrix & operator *= (HepDouble t)
- Multiply a Matrix by a floating number.
- /=
- HepMatrix & operator /= (HepDouble t)
- Divide a Matrix by a floating number.
- ()
- inline virtual const HepDouble & operator()(int row, int col)
const
- inline virtual HepDouble & operator()(int row, int col)
- Read or write a matrix element.
** Note that the indexing starts from (1,1) **
- []
- inline HepMatrix_row operator[] (int)
- inline const HepMatrix_row_const operator[] (int) const
- Read or write a matrix element.
While it may not look like it, you simply do m[i][j] to get
an element.
** Note that the indexing starts from [0][0] **
- apply
- HepMatrix apply(HepDouble (*f)(HepDouble, int, int)) const
- Apply a function to all elements of the matrix.
- determinant
- HepDouble determinant() const
- Calculate the determinant of the matrix.
- inverse
- inline HepMatrix inverse(int& ierr) const
- Invert a Matrix. Matrix must be square and is not changed.
Returns ierr = 0 (zero) when successful, otherwise non-zero.
- invert
- virtual void invert(int& ierr)
- Invert a Matrix. Matrix must be square.
N.B. the contents of the matrix are replaced by the inverse.
Returns ierr = 0 (zero) when successful,
otherwise non-zero.
This method has less overhead then inverse().
- num_col
- inline virtual int num_col() const
- Returns the number of columns.
- num_row
- inline virtual int num_row() const
- Returns the number of rows.
- sub
- HepMatrix sub(int min_row, int max_row, int min_col, int max_col)
const
- Returns a sub matrix of a Matrix.
WARNING: rows and columns are numbered from 1.
- void sub(int row, int col, const HepMatrix &m1)
- Sub matrix of this Matrix is replaced with m1.
WARNING: rows and columns are numbered from 1.
- T
- HepMatrix T() const
- Returns the transpose of a Matrix.
- trace
- HepDouble trace() const
- Calculate the trace of the matrix (sum of diagonal elements).
Non-Member Functions
- +
- HepMatrix operator + (const HepMatrix &m1,
const HepMatrix &m2)
- Adds two matrices.
Note that m += m1 is always faster than m = m + m1.
- -
- HepMatrix operator - (const HepMatrix &m1,
const HepMatrix &m2)
- Subtracts two matrices.
Note that m -= m1 is always faster than m = m - m1.
- *
- HepMatrix operator * (const HepMatrix &m1,
const HepMatrix &m2)
- HepMatrix operator * (const HepMatrix &m1,
const HepSymMatrix &m2)
- HepMatrix operator * (const HepMatrix &m1,
const HepDiagMatrix &m2)
- HepMatrix operator * (const HepSymMatrix &m1,
const HepMatrix &m2)
- HepMatrix operator * (const HepDiagMatrix &m1,
const HepMatrix &m2)
- HepMatrix operator * (const HepVector &m1,
const HepMatrix &m2)
- HepVector operator * (const HepMatrix &m1,
const HepVector &m2)
- HepMatrix operator * (const HepSymMatrix &m1,
const HepSymMatrix &m2)
- Multiply a Matrix by a Matrix or Vector.
Note that m *= m1 is always faster than m = m * m1.
- HepMatrix operator * (HepDouble t, const HepMatrix &m1)
- HepMatrix operator * (const HepMatrix &m1, HepDouble t)
- Multiplication with a number.
- /
- HepMatrix operator / (const HepMatrix &m1, HepDouble t)
- Division with a number.
Note that m /= t is faster if you can use it.
- <<
- ostream & operator << (ostream &s,
const HepMatrix &q)
- Output to a stream.
- back_solve
- void back_solve(const HepMatrix &R, HepVector *b)
- void back_solve(const HepMatrix &R, HepMatrix *b)
- Solves R*x = b where R is upper triangular.
Also has a variation that solves a number of equations of this form
in one step, where b is a matrix with each column a different
vector.
See also solve.
- col_givens
- void col_givens(HepMatrix *A, HepDouble c, HepDouble s,
int k1, int k2, int row_min=1, int row_max=0)
- Does a column Givens update.
- col_house
- void col_house(HepMatrix *a, const HepMatrix &v,
HepDouble vnormsq, int row, int col, int row_start,
int col_start)
- void col_house(HepMatrix *a, const HepMatrix &v,
int row, int col, int row_start, int col_start)
- Does a column Householder update.
- dsum
- HepMatrix dsum(const HepMatrix &, const HepMatrix &)
- Direct sum of two matrices.
The direct sum of A and B is the matrix:
A 0
0 B
- givens
- void givens(HepDouble a, HepDouble b,
HepDouble *c, HepDouble *s)
- Agorithm 5.1.5 in Golub and Van Loan
- house
- HepVector house(const HepMatrix &a, int row=1, int col=1)
- Returns a Householder vector to zero elements.
- house_with_update
- void house_with_update(HepMatrix *a, int row=1, int col=1)
- void house_with_update(HepMatrix *a, HepMatrix *v,
int row=1, int col=1)
- Finds and does Householder reflection on matrix.
- qr_decomp
- void qr_decomp(HepMatrix *A, HepMatrix *hsm)
- HepMatrix qr_decomp(HepMatrix *A)
- Does a QR decomposition of a matrix.
- qr_inverse
- HepMatrix qr_inverse(const HepMatrix &A)
- HepMatrix qr_inverse(HepMatrix *A)
- Finds the inverse of a matrix using QR decomposition.
Note, often what you really want is solve or
back_solve, they can be much quicker than inverse in many
calculations.
- qr_solve
- HepVector qr_solve(const HepMatrix &A,
const HepVector &b)
- HepVector qr_solve(HepMatrix *A, const HepVector &b)
- HepMatrix qr_solve(const HepMatrix &A,
const HepMatrix &b)
- HepMatrix qr_solve(HepMatrix *A, const HepMatrix &b)
- Works like back_solve, except matrix does not need to be upper
triangular. For nonsquare matrix, it solves in the least square sense.
- row_givens
- void row_givens(HepMatrix *A, HepDouble c, HepDouble s,
int k1, int k2, int col_min=1, int col_max=0)
- Does a row Givens update.
- row_house
- void row_house(HepMatrix *a, const HepVector &v,
HepDouble vnormsq, int row=1, int col=1)
- void row_house(HepMatrix *a, const HepMatrix &v,
HepDouble vnormsq, int row, int col, int row_start,
int col_start)
- void row_house(HepMatrix *a, const HepMatrix &v,
int row, int col, int row_start, int col_start)
- Does a row Householder update.
- solve
- HepVector solve(const HepMatrix &,
const HepVector &)
- Solve the system of linear equations using LU decomposition.
- swap
- inline void swap(HepMatrix &m1, HepMatrix &m2)
- Swap m1 with m2.
Example
CLHEP/test/testMatrix.cc
6 October 1997
EVC