ConicBundle
Classes | Namespaces | Functions
matrix.hxx File Reference

Header declaring the classes CH_Matrix_Classes::Realrange and CH_Matrix_Classes::Matrix having Real elements. More...

#include <math.h>
#include "indexmat.hxx"
#include "symmat.hxx"

Go to the source code of this file.

Classes

class  CH_Matrix_Classes::Realrange
 allows to specify a range of real values via (from, to, step,tol) meaning {x=from+i*step:x in(from-tol,to+tol),i in {0,1,2,...}} More...
 
class  CH_Matrix_Classes::Matrix
 Matrix class for real values of type Real More...
 

Namespaces

 CH_Matrix_Classes
 Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick introduction.
 

Functions

Matrix CH_Matrix_Classes::diag (const Matrix &A)
 returns a column vector v consisting of the elements v(i)=(*this)(i,i), 0<=i<min(row dimension,column dimension)
 
Matrix & CH_Matrix_Classes::xbpeya (Matrix &x, const Matrix &y, Real alpha=1., Real beta=0., int ytrans=0)
 returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to the correct size
 
Matrix & CH_Matrix_Classes::xeyapzb (Matrix &x, const Matrix &y, const Matrix &z, Real alpha=1., Real beta=1.)
 returns x= alpha*y+beta*z; x is initialized to the correct size
 
Matrix & CH_Matrix_Classes::genmult (const Matrix &A, const Matrix &B, Matrix &C, Real alpha=1., Real beta=0., int atrans=0, int btrans=0)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size
 
Matrix CH_Matrix_Classes::transpose (const Matrix &A)
 returns a transposed matrix of A
 
std::vector< double > & CH_Matrix_Classes::assign (std::vector< double > &vec, const Matrix &A)
 interpret A as a vector and copy it to a std::vector<double> which is also returned
 
Matrix & CH_Matrix_Classes::genmult (const Symmatrix &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int btrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size More...
 
Matrix & CH_Matrix_Classes::genmult (const Matrix &A, const Symmatrix &B, Matrix &C, Real alpha, Real beta, int atrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size More...
 
Matrix & CH_Matrix_Classes::genmult (const Sparsesym &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int btrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size More...
 
Matrix & CH_Matrix_Classes::genmult (const Matrix &A, const Sparsesym &B, Matrix &C, Real alpha, Real beta, int atrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size More...
 
Matrix & CH_Matrix_Classes::genmult (const Sparsemat &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int atrans, int btrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size
 
Matrix & CH_Matrix_Classes::genmult (const Matrix &A, const Sparsemat &B, Matrix &C, Real alpha, Real beta, int atrans, int btrans)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta==0. then C is initialized to the correct size
 
Matrix CH_Matrix_Classes::abs (const Matrix &A)
 returns a matrix with elements (i,j)=abs((*this)(i,j)) for all i,j
 
Real CH_Matrix_Classes::trace (const Matrix &A)
 =sum(diag(A)) More...
 
Real CH_Matrix_Classes::normDsquared (const Matrix &A, const Matrix &d, int atrans=0, int dinv=0)
 returns trace(A^TDA)=|A|^2_D with D=Diag(d). A may be transposed, D may be inverted but there is no check for division by zero
 
Matrix CH_Matrix_Classes::sumrows (const Matrix &A)
 returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
 
Matrix CH_Matrix_Classes::sumcols (const Matrix &A)
 returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
 
Real CH_Matrix_Classes::sum (const Matrix &A)
 returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
 
Matrix CH_Matrix_Classes::house (const Matrix &x, Integer i=0, Integer j=0, Real tol=1e-10)
 returns the Householder vector of size A.rowdim() for the subcolumn A(i:A.rowdim(),j)
 
int CH_Matrix_Classes::rowhouse (Matrix &A, const Matrix &v, Integer i=0, Integer j=0)
 Housholder pre-multiplication of A with Householder vector v; the first nonzero of v is index i, the multplication is applied to all columns of A with index >=j; always returns 0.
 
int CH_Matrix_Classes::colhouse (Matrix &A, const Matrix &v, Integer i=0, Integer j=0)
 Housholder post-multiplication of A with Householder vector v; the first nonzero of v is index i, the multplication is applied to all rows of A with index >=j; always returns 0.
 
Matrix CH_Matrix_Classes::operator< (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)<B(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator<= (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)<=B(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator== (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)==B(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator!= (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)!=B(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator< (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)<d) for all i,j
 
Matrix CH_Matrix_Classes::operator> (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)>d) for all i,j
 
Matrix CH_Matrix_Classes::operator<= (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)<=d) for all i,j
 
Matrix CH_Matrix_Classes::operator>= (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)>=d) for all i,j
 
Matrix CH_Matrix_Classes::operator== (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)==d) for all i,j
 
Matrix CH_Matrix_Classes::operator!= (const Matrix &A, Real d)
 returns a matrix having elements (i,j)=Real(A(i,j)!=d) for all i,j
 
Matrix CH_Matrix_Classes::minrows (const Matrix &A)
 returns a row vector holding in each column the minimum over all rows in this column
 
Matrix CH_Matrix_Classes::mincols (const Matrix &A)
 returns a column vector holding in each row the minimum over all columns in this row
 
Real CH_Matrix_Classes::min (const Matrix &A, Integer *iindex=0, Integer *jindex=0)
 returns the minimum value over all elements of the matrix
 
Matrix CH_Matrix_Classes::maxrows (const Matrix &A)
 returns a row vector holding in each column the maximum over all rows in this column
 
Matrix CH_Matrix_Classes::maxcols (const Matrix &A)
 returns a column vector holding in each row the maximum over all columns in this row
 
Real CH_Matrix_Classes::max (const Matrix &A, Integer *iindex=0, Integer *jindex=0)
 returns the maximum value over all elements of the matrix
 
Indexmatrix CH_Matrix_Classes::sortindex (const Matrix &vec, bool nondecreasing=true)
 returns an Indexmatrix ind so that vec(ind(0))<=vec(ind(1))<=...<=vec(ind(vec.dim()-1)) (vec may be rectangular, set nondecreasing=false for opposite order)
 
void CH_Matrix_Classes::sortindex (const Matrix &vec, Indexmatrix &ind, bool nondecreasing=true)
 sets ind so that vec(ind(0))<=vec(ind(1))<=...<=vec(ind(vec.dim()-1)) (vec may be rectangular, set nondecreasing=false for opposite order)
 
std::ostream & CH_Matrix_Classes::operator<< (std::ostream &o, const Matrix &v)
 output format (nr and nc are Integer values, all others Real values):
nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n
 
std::istream & CH_Matrix_Classes::operator>> (std::istream &i, Matrix &v)
 input format (nr and nc are Integer values, all others Real values):
nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n
 
Real CH_Matrix_Classes::ip (const Matrix &A, const Matrix &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
 
Real CH_Matrix_Classes::colip (const Matrix &A, Integer j, const Matrix *scaling=0)
 returns the squared Frobenius norm of column j of A, i.e., the sum of A(i,j)*A(i,j) over all i with possibly (if scaling!=0) each term i multiplied by (*scaling)(i)
 
Real CH_Matrix_Classes::rowip (const Matrix &A, Integer i, const Matrix *scaling=0)
 returns the squared Frobenius norm of row i of A, i.e., the sum of A(i,j)*A(i,j) over all j with possibly (if scaling!=0) each term j multiplied by (*scaling)(j)
 
Matrix CH_Matrix_Classes::colsip (const Matrix &A)
 returns the column vector of the squared Frobenius norm of all columns j of A, i.e., the sum of A(i,j)*A(i,j) over all i for each j
 
Matrix CH_Matrix_Classes::rowsip (const Matrix &A)
 returns the row vector of the squared Frobenius norm of all rowd i of A, i.e., the sum of A(i,j)*A(i,j) over all j for each i
 
Real CH_Matrix_Classes::norm2 (const Matrix &A)
 returns the Frobenius norm of A, i.e., the square root of the sum of A(i,j)*A(i,j) over all i,j
 
Matrix CH_Matrix_Classes::operator* (const Matrix &A, const Matrix &B)
 returns Matrix equal to A*B
 
Matrix CH_Matrix_Classes::operator+ (const Matrix &A, const Matrix &B)
 returns Matrix equal to A+B
 
Matrix CH_Matrix_Classes::operator- (const Matrix &A, const Matrix &B)
 returns Matrix equal to A-B
 
Matrix CH_Matrix_Classes::operator% (const Matrix &A, const Matrix &B)
 ATTENTION: this is redefined as the Hadamard product, C(i,j)=A(i,j)*B(i,j) for all i,j.
 
Matrix CH_Matrix_Classes::operator/ (const Matrix &A, const Matrix &B)
 ATTENTION: this is redefined to act componentwise without checking for zeros, C(i,j)=A(i,j)/B(i,j) for all i,j.
 
Matrix CH_Matrix_Classes::operator* (const Matrix &A, Real d)
 returns Matrix equal to A*d
 
Matrix CH_Matrix_Classes::operator* (Real d, const Matrix &A)
 returns Matrix equal to d*A
 
Matrix CH_Matrix_Classes::operator/ (const Matrix &A, Real d)
 returns Matrix equal to A/d; ATTENTION: d is NOT checked for 0 More...
 
Matrix CH_Matrix_Classes::operator+ (const Matrix &A, Real d)
 returns (i,j)=A(i,j)+d for all i,j
 
Matrix CH_Matrix_Classes::operator+ (Real d, const Matrix &A)
 returns (i,j)=A(i,j)+d for all i,j
 
Matrix CH_Matrix_Classes::operator- (const Matrix &A, Real d)
 returns (i,j)=A(i,j)-d for all i,j
 
Matrix CH_Matrix_Classes::operator- (Real d, const Matrix &A)
 returns (i,j)=d-A(i,j) for all i,j
 
int CH_Matrix_Classes::QR_factor (const Matrix &A, Matrix &Q, Matrix &R, Real tol)
 computes a Householder QR factorization of A and outputs Q and R leaving A unchanged; always returns 0
 
int CH_Matrix_Classes::QR_factor (const Matrix &A, Matrix &Q, Matrix &R, Indexmatrix &piv, Real tol)
 computes a Householder QR factorization of A with pivating. It outputs Q, R, and the pivoting permuation in piv; returns the rank of A
 
Matrix CH_Matrix_Classes::triu (const Matrix &A, Integer i=0)
 retuns a matrix that keeps the upper triangle of A starting with diagonal d, i.e., (i,j)=A(i,j) for 0<=i<row dimension, max(0,i+d)<=j<column dimension, and sets (i,j)=0 otherwise
 
Matrix CH_Matrix_Classes::tril (const Matrix &A, Integer i=0)
 retuns a matrix that keeps the lower triangle of A starting with diagonal d, i.e., (i,j)=A(i,j) for 0<=i<row dimension, 0<=j<min(i+d+1,column dimension), and sets (i,j)=0 otherwise
 
Matrix CH_Matrix_Classes::concat_right (const Matrix &A, const Matrix &B)
 returns a new matrix [A, B], i.e., it concats matrices A and B rowwise; A or B may be a 0x0 matrix
 
Matrix CH_Matrix_Classes::concat_below (const Matrix &A, const Matrix &B)
 returns a bew matrix [A; B], i.e., it concats matrices A and B columnwise; A or B may be a 0x0 matrix
 
void CH_Matrix_Classes::swap (Matrix &A, Matrix &B)
 swap the content of the two matrices A and B (involves no copying)
 
Matrix CH_Matrix_Classes::rand (Integer rows, Integer cols, CH_Tools::GB_rand *random_generator=0)
 return a nr x nc matrix with (i,j) assigned a random number uniformly from [0,1] for all i,j
 
Matrix CH_Matrix_Classes::inv (const Matrix &A)
 returns a matrix with elements (i,j)=1./((*this)(i,j)) for all i,j; ATTENTION: no check for division by zero
 
Matrix CH_Matrix_Classes::sqrt (const Matrix &A)
 returns a matrix with elements (i,j)=sqrt((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::sqr (const Matrix &A)
 returns a matrix with elements (i,j)=sqr((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::sign (const Matrix &A, Real tol=1e-12)
 returns a matrix with elements (i,j)=sign((*this)(i,j)) for all i,j using sign(double,double)
 
Matrix CH_Matrix_Classes::floor (const Matrix &A)
 returns a matrix with elements (i,j)=floor((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::ceil (const Matrix &A)
 returns a matrix with elements (i,j)=ceil((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::rint (const Matrix &A)
 returns a matrix with elements (i,j)=rint((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::round (const Matrix &A)
 returns a matrix with elements (i,j)=round((*this)(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator> (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)>d) for all i,j More...
 
Matrix CH_Matrix_Classes::operator>= (const Matrix &A, const Matrix &B)
 returns a matrix having elements (i,j)=Real(A(i,j)>=d) for all i,j More...
 
Matrix CH_Matrix_Classes::operator< (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d<A(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator> (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d>A(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator<= (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d<=A(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator>= (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d>=A(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator== (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d==A(i,j)) for all i,j
 
Matrix CH_Matrix_Classes::operator!= (Real d, const Matrix &A)
 returns a matrix having elements (i,j)=Real(d!=A(i,j)) for all i,j
 
bool CH_Matrix_Classes::equal (const Matrix &A, const Matrix &B)
 returns true if both matrices have the same size and the same elements
 
Indexmatrix CH_Matrix_Classes::find (const Matrix &A, Real tol=1e-10)
 returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all nonzero elements with abs(A(j))>tol
 
Indexmatrix CH_Matrix_Classes::find_number (const Matrix &A, Real num=0., Real tol=1e-10)
 returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all elements of A having value num, i.e., abs(A(j)-num)<tol
 

Detailed Description

Header declaring the classes CH_Matrix_Classes::Realrange and CH_Matrix_Classes::Matrix having Real elements.

Version
1.0
Date
2005-03-01
Author
Christoph Helmberg