Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Examples

matrix.h File Reference

Basic Matrix functionality. Provides arithmetic operators, various matrix functions and an output operator. More...

#include <complex>
#include <iostream>
#include <fstream>
#include <cstdlib>

Go to the source code of this file.

Arithmetic Operators

These are all the basic matrix arithmetic operations that you'd expect. Note that the templated scalar multiplication makes actual matrix multiplication a partial specialization. This might be too much for older MS compilers.

template<typename Z>
Matrix< Z > operator+ (const Matrix< Z > &, const Matrix< Z > &)
template<typename Z>
Matrix< Z > operator- (const Matrix< Z > &, const Matrix< Z > &)
template<typename Z>
Matrix< Z > operator * (const Z &, const Matrix< Z > &)
template<typename Z, typename S>
Matrix< Z > operator * (const S &, const Matrix< Z > &)
template<typename Z>
Matrix< Z > operator * (const Matrix< Z > &, const Matrix< Z > &)

Matrix Functions

Basic matrix functions like the Adjoint, Determinant etc that don't require any involved calculation. For the 'other' sort of matrix function see the Lapack interface Note that all these functions have reference arguments. This is to avoid an expensive copying of the Matrix argument, but contains a little gotcha. On most compilers (MS VC++ being the exception) this means that things like
 t = Trace(Adjoint(M)) 
aren't possible. You should do
 AM = Adjoint(M); t = Trace(AM); 
instead. This wouldn't happen if the functions took const refererences, but then we wouldn be able to use the element access operator M(i,j) in these functions. 'Unresolved Issue' :P

template<typename Z>
Matrix< Z > Adjoint (const Matrix< Z > &)
 Adjoint or Transpose (depending on Z).
template<typename Z>
Trace (Matrix< Z > &)
 Normal Trace.
template<typename Z>
Matrix< Z > PTrace (Matrix< Z > &R, unsigned dA, unsigned dB)
 Partial Trace.
template<typename Z>
Matrix< Z > TensorProduct (Matrix< Z > &A, Matrix< Z > &B)
 Tensor (or Kronecker or Outer) Product $A \otimes B$.
template<typename Z>
Determinant (Matrix< Z > &M)
 Determinant.
template<typename Z>
void SubMatrix (Matrix< Z > &M, Matrix< Z > &S, unsigned i, unsigned j)
 Submatrix formed by removing a given row and column.

Defines

#define PI   3.1415926535897932384626
#define SQRT2   1.41421356237309504880169
#define EABS(a)   (abs(a)<1e-15?0.0:abs(a))
#define EVAL(a)   (abs(a)<1e-14?0.0:a)

Functions

template<typename Z>
static Z gconj (const Z &other)
template<>
static std::complex< double > gconj< std::complex< double > > (const std::complex< double > &other)
template<typename Z>
std::ostream & operator<< (std::ostream &output, const Matrix< Z > &A)


Detailed Description

Basic Matrix functionality. Provides arithmetic operators, various matrix functions and an output operator.


Define Documentation

#define EABS  )     (abs(a)<1e-15?0.0:abs(a))
 

#define EVAL  )     (abs(a)<1e-14?0.0:a)
 

#define PI   3.1415926535897932384626
 

#define SQRT2   1.41421356237309504880169
 


Function Documentation

template<typename Z>
Matrix< Z > Adjoint const Matrix< Z > &   ) 
 

Adjoint or Transpose (depending on Z).

For std::complex matrices this calculates the adjoint, for real or integer matrices it returns the Transpose

template<typename Z>
Z Determinant Matrix< Z > &  M  ) 
 

Determinant.

Recursively calculates the determinant by expanding along a row. This scales horribly with matrix dimension.

template<typename Z>
static Z gconj const Z &  other  )  [static]
 

template<>
static std::complex<double> gconj< std::complex< double > > const std::complex< double > &  other  )  [static]
 

template<typename Z>
Matrix< Z > operator * const Matrix< Z > &  ,
const Matrix< Z > & 
 

template<typename Z, typename S>
Matrix< Z > operator * const S &  ,
const Matrix< Z > & 
 

template<typename Z>
Matrix< Z > operator * const Z &  ,
const Matrix< Z > & 
 

template<typename Z>
Matrix< Z > operator+ const Matrix< Z > &  ,
const Matrix< Z > & 
 

template<typename Z>
Matrix< Z > operator- const Matrix< Z > &  ,
const Matrix< Z > & 
 

template<typename Z>
std::ostream& operator<< std::ostream &  output,
const Matrix< Z > &  A
 

template<typename Z>
Matrix< Z > PTrace Matrix< Z > &  R,
unsigned  dA,
unsigned  dB
 

Partial Trace.

This is a dumb but sound way of computing the partial trace over B of an ABC system from

\[\sum_i (I_A \otimes <i| \otimes I_C) R (I_A \otimes |i> \otimes I_C)\]

dA represents the dimension of the first subsystem. dB the dimension of the system being traced over. If there is any left over, this is considered subsystem C

template<typename Z>
void SubMatrix Matrix< Z > &  M,
Matrix< Z > &  S,
unsigned  i,
unsigned  j
 

Submatrix formed by removing a given row and column.

The Matrix S is formed from M by removing row i and column j

template<typename Z>
Matrix< Z > TensorProduct Matrix< Z > &  A,
Matrix< Z > &  B
 

Tensor (or Kronecker or Outer) Product $A \otimes B$.

template<typename Z>
Z Trace Matrix< Z > &   ) 
 

Normal Trace.


Generated on Sun Jul 10 21:57:13 2005 by  doxygen 1.4.1