>
>#include <rw/dutrimat.h> // DoubleUpperTriMat #include <rw/futrimat.h> // FloatUpperTriMat #include <rw/cutrimat.h> // DComplexUpperTriMat DoubleUpperTriMat d;
The classes {TYPE}UpperTriMat encapsulate upper triangular matrices. An upper triangular matrix is 0 above the diagonal.
>#include <rw/dutrimat.h> #include <rw/dltrimat.h> main() { DoubleUpperTriMat U(5,5); DoubleLowerTriMat L = transpose(U); }>
The matrix is stored column-by-column. For example, the matrix:
is stored as follows:
[ A11 A12 A22 A13 A23 A33 ... A1n A2n A3n ... Ann ]
The mapping between the array and storage vector is as follows:
>
DoubleUpperTriMat(); FloatUpperTriMat(); DComplexUpperTriMat();
Default constructor. Builds a matrix of size 0 x 0. This constructor is necessary to declare a matrix with no explicit constructor or to declare an array of matrices.
DoubleUpperTriMat(const DoubleUpperTriMat& A); FloatUpperTriMat(const FloatUpperTriMat& A); DComplexUpperTriMat(const DComplexUpperTriMat& A);
Builds a copy of its argument, A. Note that the new matrix references A's data. To construct a matrix with its own copy of the data, you can use either the copy or deepenShallowCopy member functions.
DoubleUpperTriMat(unsigned n, unsigned n); FloatUpperTriMat(unsigned n, unsigned n); DComplexUpperTriMat(unsigned n, unsigned n);
Defines an uninitialized matrix of size n x n. Both arguments must be equal or a runtime error occurs. This constructor is used, rather than a constructor that takes only a single argument, to avoid type conversion problems.
DoubleUpperTriMat(const RWMathVec<double>& vd, unsigned n, unsigned n); FloatUpperTriMat(const RWMathVec<float>& vd, unsigned n, unsigned n); DComplexUpperTriMat(const RWMathVec<DComplex>& vd, unsigned n, unsigned n);
Constructs a size n x n matrix using the data in the passed vector. This data must be stored in the format described in the Storage Scheme section. The resultant matrix references the data in vector vd.
DComplexUpperTriMat(const DoubleUpperTriMat& re); DComplexUpperTriMat(const DoubleUpperTriMat& re, const DoubleUpperTriMat& im);
Constructs a complex matrix from the real and imaginary parts supplied. If no imaginary part is supplied, it is assumed to be 0.
DoubleUpperTriMat(const FloatUpperTriMat&);
Constructs a copy of the argument matrix with double precision entries.
ROFloatRef FloatUpperTriMat::bcref(int i, int j); RODoubleRef DoubleUpperTriMat::bcref(int i, int j); RODComplexRef DComplexUpperTriMat::bcref(int i, int j);
Returns a reference to the ijth element of the matrix, after doing bounds checking.
void FloatUpperTriMat::bcset(int i, int j, float x); void DoubleUpperTriMat::bcset(int i, int j, double x); void DComplexUpperTriMat::bcset(int i, int j, DComplex);
Sets the ijth element of the matrix equal to x, after doing bounds checking.
float FloatUpperTriMat::bcval(int i, int j); double DoubleUpperTriMat::bcval(int i, int j); DComplex DComplexUpperTriMat::bcval(int i, int j);
Returns the value of the ijth element of the matrix, after doing bounds checking.
unsigned FloatUpperTriMat::binaryStoreSize(); unsigned DoubleUpperTriMat::binaryStoreSize(); unsigned DComplexUpperTriMat::binaryStoreSize();
Returns the number of bytes that it would take to write the matrix to a file using saveOn.
unsigned FloatUpperTriMat::cols(); unsigned DoubleUpperTriMat::cols(); unsigned DComplexUpperTriMat::cols();
Returns the number of columns in the matrix.
FloatUpperTriMat FloatUpperTriMat::copy(); DoubleUpperTriMat DoubleUpperTriMat::copy(); DComplexUpperTriMat DComplexUpperTriMat::copy();
Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.
float* FloatUpperTriMat::data(); double* DoubleUpperTriMat::data(); DComplex* DComplexUpperTriMat::data();
Returns a pointer to the first item of data in the vector storing the matrix's data. You can use this (with caution!) to pass the matrix's data to C or FORTRAN subroutines. Be aware that the stride of the data vector may not be 1.
RWMathVec<float> FloatUpperTriMat::dataVec(); RWMathVec<double> DoubleUpperTriMat::dataVec(); RWMathVec<DComplex> DComplexUpperTriMat::dataVec();
Returns the matrix's data vector. This is where the explicitly stored entries in the matrix are kept.
FloatUpperTriMat FloatUpperTriMat::deepCopy(); DoubleUpperTriMat DoubleUpperTriMat::deepCopy(); DComplexUpperTriMat DComplexUpperTriMat::deepCopy();
Creates a copy of this matrix with distinct data. The stride of the data vector in the new matrix is guaranteed to be 1.
void FloatUpperTriMat::deepenShallowCopy(); void DoubleUpperTriMat::deepenShallowCopy(); void DComplexUpperTriMat::deepenShallowCopy();
Ensures that the data in the matrix is not shared by any other matrix or vector. Also ensures that the stride in the data vector is equal to 1. If necessary, a new copy of the data vector is made.
FloatUpperTriMat FloatUpperTriMat::leadingSubmatrix(int k); DoubleUpperTriMat DoubleUpperTriMat::leadingSubmatrix(int k); DComplexUpperTriMat DComplexUpperTriMat::leadingSubmatrix(int k);
Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.
void FloatUpperTriMat::printOn(ostream&); void DoubleUpperTriMat::printOn(ostream&); void DComplexUpperTriMat::printOn(ostream&);
Prints the matrix to an output stream in human readable format.
ROFloatRef FloatUpperTriMat::ref(int i, int j); RODoubleRef DoubleUpperTriMat::ref(int i, int j); RODComplexRef DComplexUpperTriMat::ref(int i, int j);
Returns a reference to the ijth element of the matrix. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcref does the same thing with guaranteed bounds checking.
FloatUpperTriMat FloatUpperTriMat::reference(FloatUpperTriMat&); DoubleUpperTriMat DoubleUpperTriMat::reference(DoubleUpperTriMat&); DComplexUpperTriMat DComplexUpperTriMat::reference(DComplexUpperTriMat&);
Makes this matrix a reference to the argument matrix. The two matrices share the same data. The matrices do not have to be the same size before calling reference. To copy a matrix into another of the same size, use the operator= member operator.
void DoubleUpperTriMat::resize(unsigned n, unsigned n); void FloatUpperTriMat::resize(unsigned n, unsigned n); void DComplexUpperTriMat::resize(unsigned n, unsigned);
Resizes the matrix. Any new entries in the matrix are set to 0. Both arguments must be the same.
void DoubleUpperTriMat::restoreFrom(RWFile&); void FloatUpperTriMat::restoreFrom(RWFile&); void DComplexUpperTriMat::restoreFrom(RWFile&);
Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn member function.
void DoubleUpperTriMat::restoreFrom(RWvistream&); void FloatUpperTriMat::restoreFrom(RWvistream&); void DComplexUpperTriMat::restoreFrom(RWvistream&);
Reads in a matrix from an RWvistream, the Rogue Wave virtual input stream class. The matrix must have been stored to the stream using the saveOn member function.
unsigned FloatUpperTriMat::rows(); unsigned DoubleUpperTriMat::rows(); unsigned DComplexUpperTriMat::rows();
Returns the number of rows in the matrix.
void DoubleUpperTriMat::saveOn(RWFile&); void FloatUpperTriMat::saveOn(RWFile&); void DComplexUpperTriMat::saveOn(RWFile&);
Stores a matrix to an RWFile. The matrix can be read using the restoreFrom member function.
void DoubleUpperTriMat::saveOn(RWvostream&); void FloatUpperTriMat::saveOn(RWvostream&); void DComplexUpperTriMat::saveOn(RWvostream&);
Stores a matrix to an RWvostream, the Rogue Wave virtual output stream class. The matrix can be read using the restoreFrom member function.
void FloatUpperTriMat::scanFrom(istream&); void DoubleUpperTriMat::scanFrom(istream&); void DComplexUpperTriMat::scanFrom(istream&);
Reads a matrix from an input stream. The format of the matrix is the same as the format output by the printTo member function. Below is a sample matrix that could be input. Note that extra white space and any text preceding the dimension specification are ignored. Only the upper triangle of the matrix is used.
4x4 [ 4 3 3 9 0 9 -1 5 0 0 3 1 0 0 0 -2 ]
void FloatUpperTriMat::set(int i, int j, float x); void DoubleUpperTriMat::set(int i, int j, double x); void DComplexUpperTriMat::set(int i, int j, DComplex x);
Sets the ijth element of the matrix equal to x. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcset does the same thing with guaranteed bounds checking.
float FloatUpperTriMat::val(int i, int j); double DoubleUpperTriMat::val(int i, int j); DComplex DComplexUpperTriMat::val(int i, int j);
Returns the value of the ijth element of the matrix. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcval does the same thing with guaranteed bounds checking.
FloatUpperTriMat FloatUpperTriMat::zero(); DoubleUpperTriMat DoubleUpperTriMat::zero(); DComplexUpperTriMat DComplexUpperTriMat::zero();
Sets every element of the matrix to 0.
RODoubleRef FloatUpperTriMat::operator()(int i, int j); double FloatUpperTriMat::operator()(int i,
int j) const; ROFloatRef DoubleUMat::operator()(int i, int j); float DoubleUpperTriMat::operator()(int i,
int j) const; RODComplexRef DComplexUpperTriMat::operator()(int i, int j); DComplex DComplexUpperTriMat::operator()(int i,
int j)const;
Accesses the ijth element. If the matrix is not a const matrix, a reference type is returned, so this operator can be used for assigning or accessing an element. In this case, using this operator is equivalent to calling the ref member function. If the matrix is a const matrix, then a value is returned, so this operator can be used only for accessing an element. In this case, using this operator is equivalent to calling the val member function. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined before including the header file.
DoubleUpperTriMat& operator=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator=(const DComplexUpperTriMat& A);
Sets the matrix elements equal to the elements of A. The two matrices must be the same size. To make the matrix reference the same data as A, you can use the reference member function.
DoubleUpperTriMat& operator==(const DoubleUpperTriMat& A); FloatUpperTriMat& operator==(const FloatUpperTriMat& A); DComplexUpperTriMat& operator==(const DComplexUpperTriMat& A); DoubleUpperTriMat& operator!=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator!=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator!=(const DComplexUpperTriMat& A);
Boolean operators. Two matrices are considered equal if they have the same size and their elements are all exactly the same. Be aware that floating point arithmetic is not exact; matrices that are theoretically equal are not always numerically equal.
DoubleUpperTriMat& operator*=(double x); FloatUpperTriMat& operator*=(float x); DComplexUpperTriMat& operator*=(DComplex x); DoubleUpperTriMat& operator/=(double x); FloatUpperTriMat& operator/=(float x); DComplexUpperTriMat& operator/=(DComplex x);
Performs the indicated operation on each element of the matrix.
DoubleUpperTriMat& operator+=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator+=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator+=(const DComplexUpperTriMat& A); DoubleUpperTriMat& operator-=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator-=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator-=(const DComplexUpperTriMat& A); DoubleUpperTriMat& operator*=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator*=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator*=(const DComplexUpperTriMat& A); DoubleUpperTriMat& operator/=(const DoubleUpperTriMat& A); FloatUpperTriMat& operator/=(const FloatUpperTriMat& A); DComplexUpperTriMat& operator/=(const DComplexUpperTriMat& A);
Performs element-by-element arithmetic on the data in the matrices. In particular, note that operator*= does element-by-element multiplication, not inner product style matrix multiplication. Use the product global function to do matrix-matrix inner product multiplication.
DoubleUpperTriMat operator+(const DoubleUpperTriMat&); FloatUpperTriMat operator+(const FloatUpperTriMat&); DComplexUpperTriMat operator+(const DComplexUpperTriMat&); DoubleUpperTriMat operator-(const DoubleUpperTriMat&); FloatUpperTriMat operator-(const FloatUpperTriMat&); DComplexUpperTriMat operator-(const DComplexUpperTriMat&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
DoubleUpperTriMat operator+(const DoubleUpperTriMat&,
const DoubleUpperTriMat&); FloatUpperTriMat operator+(const FloatUpperTriMat&,
const FloatUpperTriMat&); DComplexUpperTriMat operator+(const DComplexUpperTriMat&,
const DComplexUpperTriMat&); DoubleUpperTriMat operator-(const DoubleUpperTriMat&,
const DoubleUpperTriMat&); FloatUpperTriMat operator-(const FloatUpperTriMat&,
const FloatUpperTriMat&); DComplexUpperTriMat operator-(const DComplexUpperTriMat&,
const DComplexUpperTriMat&); DoubleUpperTriMat operator*(const DoubleUpperTriMat&,
const DoubleUpperTriMat&); FloatUpperTriMat operator*(const FloatUpperTriMat&,
const FloatUpperTriMat&); DComplexUpperTriMat operator*(const DComplexUpperTriMat&,
const DComplexUpperTriMat&); DoubleUpperTriMat operator/(const DoubleUpperTriMat&,
const DoubleUpperTriMat&); FloatUpperTriMat operator/(const FloatUpperTriMat&,
const FloatUpperTriMat&); DComplexUpperTriMat operator/(const DComplexUpperTriMat&,
const DComplexUpperTriMat&);
Performs element by element operations on the arguments. To do inner product matrix multiplication, you can use the product global function.
DoubleUpperTriMat operator*(double,
const DoubleUpperTriMat&); DoubleUpperTriMat operator*(const DoubleUpperTriMat&,
double); FloatUpperTriMat operator*(float,const FloatUpperTriMat&); FloatUpperTriMat operator*(const FloatUpperTriMat&,float); DComplexUpperTriMat operator*(DComplex,
const DComplexUpperTriMat&); DComplexUpperTriMat operator*(const DComplexUpperTriMat&,
DComplex); DoubleUpperTriMat operator/(const DoubleUpperTriMat&,
double); FloatUpperTriMat operator/(const FloatUpperTriMat&,
float); DComplexUpperTriMat operator/(const DComplexUpperTriMat&,
DComplex);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s, const DoubleUpperTriMat&); ostream& operator<<(ostream& s, const FloatUpperTriMat&); ostream& operator<<(ostream& s, const DComplexUpperTriMat&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s, const DoubleUpperTriMat&); istream& operator>>(istream& s, const FloatUpperTriMat&); istream& operator>>(istream& s const DComplexUpperTriMat&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
DoubleUpperTriMat abs(const DoubleUpperTriMat&); FloatUpperTriMat abs(const FloatUpperTriMat&); DoubleUpperTriMat abs(const DComplexUpperTriMat&);
Returns a matrix whose entries are the absolute value of the argument. The absolute value of a complex number is considered to be the sum of the absolute values of its real and imaginary parts. To get the norm of a complex matrix, you can use the norm function.
DoubleUpperTriMat arg(const DComplexUpperTriMat& A);
Returns a matrix where each element is the argument of the corresponding element in the matrix A.
DComplexUpperTriMat conj(const DComplexUpperTriMat& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
DoubleUpperTriMat imag(const DComplexUpperTriMat& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
double maxValue(const DoubleUpperTriMat&); float maxValue(const FloatUpperTriMat&); double minValue(const DoubleUpperTriMat&); float minValue(const FloatUpperTriMat&);
Returns the maximum or minimum entry in the matrix.
DoubleUpperTriMat norm(const DComplexUpperTriMat& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
RWMathVec<double> product(const DoubleUpperTriMat& A, const RWMathVec<double>& x); RWMathVec<float> product(const FloatUpperTriMat& A, const RWMathVec<float>& x); RWMathVec<DComplex> product(const DComplexUpperTriMat& A, const RWMathVec<DComplex>& x);
Returns the inner product (matrix-vector product) of A and x.
RWMathVec<double> product(const RWMathVec<double>& x, const DoubleUpperTriMat& A); RWMathVec<float> product(const RWMathVec<float>& x, const FloatUpperTriMat& A); RWMathVec<DComplex> product(const RWMathVec<DComplex>& x, const DComplexUpperTriMat& A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
DoubleUpperTriMat real(const DComplexUpperTriMat& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
FloatUpperTriMat toFloat(const DoubleUpperTriMat&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
DoubleUpperTriMat toUpperTriMat(const RWGenMat<double>&); FloatUpperTriMat toUpperTriMat(const RWGenMat<float>&); DComplexUpperTriMat toUpperTriMat(const RWGenMat<DComplex>&);
Extracts the upper triangular part of a square matrix.
DoubleLowerTriMat transpose(const DoubleUpperTriMat&); FloatLowerTriMat transpose(const FloatUpperTriMat&); DComplexLowerTriMat transpose(const DComplexUpperTriMat&);
Returns the transpose of the argument matrix. The transpose is made to reference the same data as the argument matrix.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.