HepSymMatrix


This is very much like the HepMatrix, except of course it is restricted to Symmetric Matrix. All the operations for HepMatrix can also be done here (except for the +=, -=, *= that don't yield a symmetric matrix. e.g. +=(const Matrix &) is not defined)

The matrix is stored as a lower triangular matrix. In addition to the (row, col) method of finding element, fast(row, col) returns an element with checking to see if row and col need to be interchanged so that row >= col.

Author

Mike Smyth

See also

HepGenMatrix, HepMatrix, HepDiagMatrix, HepVector, HepPile,

Declaration

#include "CLHEP/Matrix/SymMatrix.h"

class HepSymMatrix : public HepGenMatrix

Public Member Classes

HepSymMatrix_row
Helper class to implement m[i][j]
Declaration
class HepSymMatrix_row
Constructor
inline HepSymMatrix_row(HepSymMatrix&, int)
[]
inline HepDouble & operator[](int)

HepSymMatrix_row_const
Helper class to implement m[i][j]
Declaration
class HepSymMatrix_row_const
Constructor
inline HepSymMatrix_row_const(const HepSymMatrix&, int)
[]
inline const HepDouble & operator[](int) const

Public Member Functions

Constructor
inline HepSymMatrix()
Default constructor. Gives 0 x 0 symmetric matrix.
Another HepSymMatrix can be assigned to it.
Constructor
HepSymMatrix(int p)
HepSymMatrix(int p, int)
Gives p x p symmetric matrix.
With a second argument, the matrix is initialized.
0 means a zero matrix, 1 means the identity matrix.
Constructor
#ifdef HEP_USE_RANDOM
HepSymMatrix(int p, HepRandom &r)
#endif
Constructor with a Random object.
Constructor
HepSymMatrix(const HepDiagMatrix &m1)
Constructor from HepDiagMatrix.
Copy constructor
HepSymMatrix(const HepSymMatrix &m1)
Destructor
virtual ~HepSymMatrix()
=
HepSymMatrix & operator = (const HepSymMatrix &m2)
HepSymMatrix & operator = (const HepDiagMatrix &m2)
Assignment operators. Notice that there is no HepSymMatrix = HepMatrix.
+=
HepSymMatrix & operator += (const HepSymMatrix &m2)
HepSymMatrix & operator += (const HepDiagMatrix &m2)
Add a HepSymMatrix.
-
HepSymMatrix operator - () const
Unary minus, i.e. flip the sign of each element.
-=
HepSymMatrix & operator -= (const HepSymMatrix &m2)
HepSymMatrix & operator -= (const HepDiagMatrix &m2)
Subtract a HepSymMatrix.
*=
HepSymMatrix & operator *= (HepDouble t)
Multiply a HepSymMatrix by a floating number.
/=
HepSymMatrix & operator /= (HepDouble t)
Divide a HepSymMatrix by a floating number.
()
const HepDouble & operator()(int row, int col) const
HepDouble & operator()(int row, int col)
Read and write a HepSymMatrix element.
** Note that indexing starts from (1,1) **
[]
inline HepSymMatrix_row operator[] (int)
inline HepSymMatrix_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
HepSymMatrix apply(HepDouble (*f)(HepDouble, int, int)) const
Apply a function to all elements of the matrix.
assign
void assign(const HepMatrix &m2)
Assigns m2 to s, assuming m2 is a symmetric matrix.

void assign(const HepSymMatrix &)
Another form of assignment. For consistency.
determinant
HepDouble determinant() const
Calculate the determinant of the matrix.
fast
const HepDouble & fast(int row, int col) const
HepDouble & fast(int row, int col)
Fast element access. Must be row >= col.
** Note that indexing starts from (1,1) **
inverse
inline HepSymMatrix inverse(int &ifail) const
Invert a HepSymMatrix. The matrix is not changed.
Returns 0 when successful, otherwise non-zero.

This inverse function has been taken from dsinv of CERNLIB. This function works with symmetric positive definit matrix only. If the the matrix is NOT positive definit, the inverse returns ifail of non-zero. Be sure to check this.

invert
void invert(int &ifail)
Invert a HepSymMatrix.
N.B. the contents of the matrix are replaced by the inverse.
Returns ifail = 0 (zero) when successful, otherwise non-zero.
This method has less overhead then inverse().

This invert function has been taken from dsinv of CERNLIB. This function works with symmetric positive definit matrix only. If the the matrix is NOT positive definit, the invert returns ifail of non-zero. Be sure to check this.

num_col
inline int num_col() const
Returns number of columns.
num_row
inline int num_row() const
Returns number of rows.
similarity
HepSymMatrix similarity(const HepMatrix &m1) const
HepSymMatrix similarity(const HepSymMatrix &m1) const
Returns m1*s*m1.T()

HepDouble similarity(const HepVector &v) const
Returns v.T()*s*v (This is a scaler).
similarityT
HepSymMatrix similarityT(const HepMatrix &m1) const
Temporary. Test of new similarity.
Returns m1.T()*s*m1
sub
HepSymMatrix sub(int min_row, int max_row) const
Returns a sub matrix of a HepSymMatrix.

void sub(int row, const HepSymMatrix &m1)
Sub matrix of this HepSymMatrix is replaced with m1.

#ifdef HEP_CC_NEED_SUB_WITHOUT_CONST
HepSymMatrix sub(int min_row, int max_row)
#endif
SGI CC bug. I have to have both with/without const. I should not need one without const.
T
HepSymMatrix T() const
Returns the transpose of a HepSymMatrix (which is itself).
trace
HepDouble trace() const
Calculate the trace of the matrix (sum of diagonal elements).

Non-Member Functions

+
HepMatrix operator + (const HepMatrix &m1, const HepSymMatrix &s2)
HepMatrix operator + (const HepSymMatrix &s1, const HepMatrix &m2)
HepSymMatrix operator + (const HepSymMatrix &s1, const HepSymMatrix &s2)
Addition operators.
-
HepMatrix operator - (const HepMatrix &m1, const HepSymMatrix &s2)
HepMatrix operator - (const HepSymMatrix &s1, const HepMatrix &m2)
HepSymMatrix operator - (const HepSymMatrix &s1, const HepSymMatrix &s2)
Subtraction operators.
*
HepMatrix operator * (const HepMatrix &m1, const HepSymMatrix &m2)
HepMatrix operator * (const HepSymMatrix &m1, const HepMatrix &m2)
HepMatrix operator * (const HepSymMatrix &m1, const HepSymMatrix &m2)
HepVector operator * (const HepSymMatrix &m1, const HepVector &m2)
Multiplication operators.
Note that m *= m1 is always faster than m = m * m1

HepSymMatrix operator * (HepDouble t, const HepSymMatrix &s1)
HepSymMatrix operator * (const HepSymMatrix &s1, HepDouble t)
Multiplication with a number.
/
HepSymMatrix operator / (const HepSymMatrix &s1, HepDouble t)
Division with a number.
Note that s /= t is faster if you can use it.
<<
HepStd::ostream & operator << (HepStd::ostream &s, const HepSymMatrix &q)
Output to a stream.
condition
HepDouble condition(const HepSymMatrix &m)
Find the condition number of a symmetric matrix.
diagonalize
HepMatrix diagonalize(HepSymMatrix *s)
Diagonalize a symmetric matrix.
It returns the matrix U so that s_old = U * s_diag * U.T()
diag_step
void diag_step(HepSymMatrix *t, int begin, int end)
void diag_step(HepSymMatrix *t, HepMatrix *u, int begin, int end)
Implicit symmetric QR step with Wilkinson Shift.
dsum
HepSymMatrix dsum(const HepSymMatrix &s1, const HepSymMatrix &s2)
Direct sum of two symmetric matrices.
house
HepVector house(const HepSymMatrix &a, int row=1, int col=1)
Returns a Householder vector to zero elements.
house_with_update2
void house_with_update2(HepSymMatrix *a, HepMatrix *v, int row=1, int col=1)
Finds and does Householder reflection on matrix.
tridiagonal
void tridiagonal(HepSymMatrix *a, HepMatrix *hsm)
HepMatrix tridiagonal(HepSymMatrix *a)
Does a Householder tridiagonalization of a symmetric matrix.
vT_times_v
HepSymMatrix vT_times_v(const HepVector &v)

Example

CLHEP/test/testMatrix.cc


19 June 2001
EVC