Functions

MatrixTools.hh File Reference

#include <fstream.h>
#include "ocsTools.hh"

Go to the source code of this file.

Functions

void CopyMatrix (double **LHS_Matrix, double **RHS_Matrix, int dim)
 Matrix Assignment LHS_Matrix = RHS_Matrix.
void DenseMatrixProduct (double **A, double **B, double **R, bool Transpose_B, bool R_is_symmetric, int dim)
void DenseMatrixSimilarityProduct (double **A, double **B, double **R, double **Work, bool Transpose_A, bool R_is_symmetric, int dim)
void DenseMatrixScale (double **A, int dim, double scale)
 Multiply all elements of the dim x dim double matrix A by the double scale.
void CopyLowerToUpperHalf (double **A, int dim)
void SymmetrizeMatrix (double **A, int dim)
 Replaces A with 0.5*(A+A') where A' is the transpose of the real matrix A.
void TransposeMatrix (double **A, int dim)
 If input[i][j] = A_ij then output[i][j]= A_ji.
void ZeroMatrix (double **A, int dim)
 Sets all entries of Matrix A to 0.
void DenseMatrixFilter (double **A, int dim, double *filter)
 Filters the matrix A with filter.
void WriteMatrix (double **A, int dim, ofstream *F, double scaler)
 Writes the Matrix scaling*A of size dim x dim to the file F.
void ReadMatrix (double **A, int dim, ifstream *F, double scaling)
void DenseMatrixVectorProduct (double *Out, double **A, double *In, int dim)
void DenseVectorMatrixProduct (double *Out, double *In, double **A, int dim)
void AddToPrincipalDiag (double **A, int dim, double add)
 Adds the double add to the principal diagonal of Matrix A.
void AddVectorToPrincipalDiag (double **A, double *V, double ScalarMultiple, int dim)
double ScalarProductNormalized (cplx *aa, cplx *bb, int len)
double VectorAngle (cplx *aa, cplx *bb, int len)
void SchmidtOrthogonalizer (cplx **vec, int num, int len, double *alpha)
void SchmidtOrthogonalizer (cplx **vec, int num, int len, double *alpha, int k1)
double InfNormMatrix (double **A, int dim)
double OneNormMatrix (double **A, int dim)
double InnerProduct (double *V, double *W, int Length)
 Returns the standard inner product of two real vectors.

Function Documentation

void AddToPrincipalDiag ( double **  A,
int  dim,
double  add 
)
void AddVectorToPrincipalDiag ( double **  A,
double *  V,
double  ScalarMultiple,
int  dim 
)

Adds the array ScalarMultiple*V, where V is a vector to the principal diagonal of Matrix A.

Referenced by ChiSquareReceiver::TestEigDecomposition().

void CopyLowerToUpperHalf ( double **  A,
int  dim 
)

Copies the lower half of the matrix A to the upper half, so that the resulting matrix is symmetric.

Copies the lower half of the matrix A to the upper half, so that the resulting matrix is symmetric.

A: real matrix of dimension dim x dim indices run from 0 to dim-1 A[row][column]

Referenced by DenseMatrixProduct().

void CopyMatrix ( double **  LHS_Matrix,
double **  RHS_Matrix,
int  dim 
)

Matrix Assignment LHS_Matrix = RHS_Matrix.

Referenced by NoiseCovariance::operator=(), and ChiSquareReceiver::SymmetricEig().

void DenseMatrixFilter ( double **  A,
int  dim,
double *  filter 
)

Filters the matrix A with filter.

If A[i][j] is the (i,j) entry of A, and filter[i] is the i-th element of filter, then the filtering of A is defined to be

A_new[i][j] = A_old[i][j]*filter[i]*filter[j]

where * is regular multiplication of numbers.

void DenseMatrixProduct ( double **  A,
double **  B,
double **  R,
bool  Transpose_B,
bool  R_is_symmetric,
int  dim 
)

Computes the matrix product R = A * B or R = A * B^T depending on whether the flag Transpose_B is 0 or 1.

Computes the matrix product R = A * B or R = A * B^T depending on whether the flag Transpose_B is 0 or 1.

A,B, and R are all real matrices of dimension dim x dim where indices run from 0 to dim-1. It is assumed that all matrices are double 2D arrays with M[i][j] being the (row,col) = (i,j) of the Matrix M.

References CopyLowerToUpperHalf().

Referenced by ChiSquareReceiver::ComputeKLModes(), DenseMatrixSimilarityProduct(), ChiSquareReceiver::TestEigDecomposition(), and NoiseCovariance::UpdateCovMatrixODE().

void DenseMatrixScale ( double **  A,
int  dim,
double  scale 
)

Multiply all elements of the dim x dim double matrix A by the double scale.

A is a real matrix of dimension dim x dim where indices run from 0 to dim-1. A is a double 2D array with A[i][j] being the (row,col) = (i,j) of the Matrix A.

Referenced by NoiseCovariance::AmplifyCovarianceMatrix(), ChiSquareReceiver::GetReducedNoiseFreeSigAndDiagonalizeCovMatrix(), and NoiseCovariance::LumpedLossCovarianceMatrix().

void DenseMatrixSimilarityProduct ( double **  A,
double **  B,
double **  R,
double **  Work,
bool  Transpose_A,
bool  R_is_symmetric,
int  dim 
)

Computes the matrix product R = A*B*A^T or R = A^T*B*A depending on whether the flag Transpose_A is 0 or 1, respectively

Computes the matrix product R = A*B*A^T or R = A^T*B*A depending on whether the flag Transpose_A is 0 or 1, respectively

A,B,R, and Work are all real matrices of dimension dim x dim where indices run from 0 to dim-1. It is assumed that all matrices are double 2D arrays with M[i][j] being the (row,col) = (i,j) of the Matrix M.

References DenseMatrixProduct(), and TransposeMatrix().

Referenced by ChiSquareReceiver::ComputeKLModes(), and ChiSquareReceiver::TestEigDecomposition().

void DenseMatrixVectorProduct ( double *  Out,
double **  A,
double *  In,
int  dim 
)

Computes the matrix-vector product Out = A*In where In and Out are vectors and A is square of size dim x dim

Referenced by ChiSquareReceiver::ComputeKLModes().

void DenseVectorMatrixProduct ( double *  Out,
double *  In,
double **  A,
int  dim 
)

Computes the matrix-vector product Out = In*A where In and Out are vectors and A is square of size dim x dim

double InfNormMatrix ( double **  A,
int  dim 
)

The infinity norm of a square matrix A is the largest row sum of the matrix whose entries are the absolute values of A

Referenced by OneNormMatrix(), and ChiSquareReceiver::TestEigDecomposition().

double InnerProduct ( double *  V,
double *  W,
int  Length 
)
double OneNormMatrix ( double **  A,
int  dim 
)

The one norm of a square matrix A is the largest column sum of the matrix whose entries are the absolute values of A

References InfNormMatrix(), and TransposeMatrix().

void ReadMatrix ( double **  A,
int  dim,
ifstream *  F,
double  scaling 
)

Reads in the Matrix scaling*A of size dim x dim from the file F that was previously written using WriteMatrix

Reads in the Matrix scaling*A of size dim x dim from the file F that was previously written using WriteMatrix

The i-th row of the file contains the i-th row of A

Referenced by NoiseCovariance::ReadFileNoiseFreeSignalAndCovarianceMatrix().

double ScalarProductNormalized ( cplx aa,
cplx bb,
int  len 
)

Returns the double (aa,bb)/(bb,bb) for aa, bb complex vectors of length len where (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

Referenced by SchmidtOrthogonalizer().

void SchmidtOrthogonalizer ( cplx **  vec,
int  num,
int  len,
double *  alpha 
)

Performs Gram-Schmidt orthogonalization of num vectors of length len where vec[i][] is the i-th vector i.e., vec is a cplx array of dim num x len alpha[] must be a double array of length (num^2-num)/2 Can start orthogonalization proceedure with the k1-th vector instead of the 1-st vector if you like. (k1 is an optional argument). Uses the inner product (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

Performs Gram-Schmidt orthogonalization of num vectors of length len where vec[i][] is the i-th vector i.e., vec is a cplx array of dim num x len alpha[] must be a double array of length (num^2-num)/2 Can start orthogonalization proceedure with the k1-th vector instead of the 1-st vector if you like. (k1 is an optional argument). Uses the inner product (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

Input: Set of num vectors of length len that span a linear space

Output: Orthogonalized set of num vectors in vec. vec[0][] is untouched, the component of vec[1][] that is parallel to vec[0][] is removed from vec[1][], then the component of vec[2][] that is parallel to vec[0][] is removed from vec[2][], then the component of vec[2][] that is parallel to vec[1][] is removed etc...

Method: Schmidt's orthogonalization procedure, see "Taschenbuch der Mathematik", p. 147 alpha[] must be a double array of length (num^2-num)/2 that will contain the normalized scalar products (a_2,b_1)/(b_1,b_1), (a_3,b_1)/(b_1,b_1), (a_3,b_2)/(b_2,b_2), (a_4,b_1)/(b_1,b_1), (a_4,b_2)/(b_2,b_2), (a_4,b_3)/(b_3,b_3),...

vec[][]: cplx array of dim num x len k1: optional argument, start index (index of b_i to start with)

Successfully tested 25 Feb 2001 R.H. for vectors of length 3: vec[0][0] = 2.0; vec[0][1] = 3.0; vec[0][2] = -1.0; vec[1][0] = -5.0; vec[1][1] = 7.0; vec[1][2] = -3.0; vec[2][0] = 1.0; vec[2][1] = 2.0; vec[2][2] = 9.0; schmidt_orthogonalizer(vec, 3, 3, alpha);

References SchmidtOrthogonalizer().

Referenced by NoiseCovariance::ComputeColumnPropagator(), and SchmidtOrthogonalizer().

void SchmidtOrthogonalizer ( cplx **  vec,
int  num,
int  len,
double *  alpha,
int  k1 
)
void SymmetrizeMatrix ( double **  A,
int  dim 
)

Replaces A with 0.5*(A+A') where A' is the transpose of the real matrix A.

Referenced by ChiSquareReceiver::ComputeKLModes(), and ChiSquareReceiver::GetReducedNoiseFreeSigAndDiagonalizeCovMatrix().

void TransposeMatrix ( double **  A,
int  dim 
)
double VectorAngle ( cplx aa,
cplx bb,
int  len 
)

Returns the angle between complex vectors aa and bb of length len using the inner product (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

Returns the angle between complex vectors aa and bb of length len using the inner product (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

Computes acos((aa,bb)/(|bb|*|aa|)) for aa, bb complex vectors of length len where (aa,bb) := Re[conj(aa) * bb] = Re(aa)*Re(bb) + Im(aa)*Im(bb)

References sqrt().

void WriteMatrix ( double **  A,
int  dim,
ofstream *  F,
double  scaling 
)

Writes the Matrix scaling*A of size dim x dim to the file F.

The i-th row of the file contains the i-th row of A

Referenced by NoiseCovariance::WriteFileNoiseFreeSignalAndCovarianceMatrix(), and ChiSquareReceiver::WriteFileSquareMatrix().

void ZeroMatrix ( double **  A,
int  dim 
)