>
>#include <rw/dbandmat.h> // DoubleBandMat #include <rw/cbandmat.h> // DComplexBandMat #include <rw/fbandmat.h> // FloatBandMat DoubleBandMat d;
The classes {TYPE}BandMat encapsulate a banded matrix. A banded matrix is nonzero only near the diagonal. Specifically, if u is the upper bandwidth and l the lower, the matrix entry Aij is defined as 0 if either j-i>u or i-j>l. The total bandwidth, simply called bandwidth, is the sum of the upper and lower bandwidths plus 1, for the diagonal. See the Storage Scheme section of this entry for an example of a banded matrix.
>#include <rw/dbandmat.h> #include <rw/rstream.h>
main(){
DoubleBandMat d(9, 9, 2, 1);
d.diagonal(-2) = 1; d.diagonal(-1) = 2; d.diagonal( ) = 3; d.diagonal( 1) = 4;
cout << d; }>
The matrix is stored column-by-column. There are some unused locations in the vector of data so that each column takes up the same number of entries. For example, the following 9x9 matrix has an upper bandwidth of 1, a lower bandwidth of 2, and thus a total bandwidth of 4:
This matrix is stored as follows:
[ XXX A11 A21 A31 A12 A22 A32 A42 A23 A33 A43 A53
A34 A44 A54 A64 A45 A55 A65 A75 A56 A66 A76 A86
A67 A77 A87 A97 A78 A88 A98 XXX A89 A99 XXX XXX ]
where XXX indicates an unused storage location. The mapping between array entry Aij and the storage vector is as follows:
>
DoubleBandMat(); FloatBandMat(); DComplexBandMat();
Default constructor. Builds a matrix of size 0 by 0. Necessary for declaring a matrix with no explicit constructor, or an array of matrices.
DoubleBandMat(const DoubleBandMat& A); FloatBandMat(const FloatBandMat& A); DComplexBandMat(const DComplexBandMat& A);
Builds a copy of the argument, A. Note that the new matrix references A's data. To construct a matrix with its own copy of the data, use either the copy or deepenShallowCopy member functions.
DoubleBandMat(unsigned n, unsigned n, unsigned lb,
unsigned ub); FloatBandMat(unsigned n, unsigned n, unsigned lb,
unsigned ub); DComplexBandMat(unsigned n, unsigned n, unsigned lb,
unsigned ub);
Defines an uninitialized matrix of size n x n with lower bandwidth lb and upper bandwidth ub.
DoubleBandMat(const RWMathVec<double>& vd, unsigned n,
unsigned n,unsigned lb, unsigned ub); FloatBandMat(const RWMathVec<float>& vd, unsigned n,
unsigned n, unsigned lb, unsigned ub); DComplexBandMat(const RWMathVec<DComplex>& vd, unsigned n
unsigned n, unsigned lb, unsigned ub);
Constructs a size n x n matrix, with lower bandwidth lb and upper bandwidth ub, 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.
DComplexBandMat(const DoubleBandMat& re); DComplexBandMat(const DoubleBandMat& re, const DoubleBandMat& im);
Constructs a complex matrix from the real and imaginary parts supplied. If no imaginary part is supplied, it is assumed to be 0.
DoubleBandMat(const FloatBandMat&);
Constructs a copy of the argument matrix with double precision entries.
FloatBandMat(const FloatSymBandMat&); DoubleBandMat(const FloatSymBandMat&); DComplexBandMat(const DComplexSymBandMat&); DComplexBandMat(const DComplexHermBandMat&); FloatBandMat(const FloatTriDiagMat&); DoubleBandMat(const DoubleTriDiagMat&); DComplexBandMat(const DComplexTriDiagMat&);
Constructs a banded matrix from a symmetric banded, Hermitian banded, or tridiagonal matrix.
unsigned FloatBandMat::bandwidth(); unsigned DoubleBandMat::bandwidth(); unsigned DComplexBandMat::bandwidth();
Returns the bandwidth of the matrix. The bandwidth is the sum of the upper and lower bandwidths plus 1 for the main diagonal.
RWMathVec<float> FloatBandMat::bcdiagonal(int j=0); RWMathVec<double> DoubleBandMat::bcdiagonal(int j=0); RWMathVec<DComplex> DComplexBandMat::bcdiagonal(int j=0);
Returns a reference to the jth diagonal of the matrix, after doing bounds checking. The main diagonal is indexed by 0, diagonals in the upper triangle are indexed with positive integers, and diagonals in the lower triangle are indexed with negative integers.
ROFloatRef FloatBandMat::bcref(int i, int j); RODoubleRef DoubleBandMat::bcref(int i, int j); RODComplexRef DComplexBandMat::bcref(int i, int j);
Returns a reference to the ijth element of the matrix, after doing bounds checking.
void FloatBandMat::bcset(int i, int j, float x); void DoubleBandMat::bcset(int i, int j, double x); void DComplexBandMat::bcset(int i, int j, DComplex x);
Sets the ijth element of the matrix equal to x, after doing bounds checking.
float FloatBandMat::bcval(int i, int j); double DoubleBandMat::bcval(int i, int j); DComplex DComplexBandMat::bcval(int i, int j);
Returns the value of the ijth element of the matrix, after doing bounds checking.
unsigned FloatBandMat::binaryStoreSize(); unsigned DoubleBandMat::binaryStoreSize(); unsigned DComplexBandMat::binaryStoreSize();
Returns the number of bytes that it would take to write the matrix to a file using saveOn.
unsigned FloatBandMat::cols(); unsigned DoubleBandMat::cols(); unsigned DComplexBandMat::cols();
Returns the number of columns in the matrix.
FloatBandMat FloatBandMat::copy(); DoubleBandMat DoubleBandMat::copy(); DComplexBandMat DComplexBandMat::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* FloatBandMat::data(); double* DoubleBandMat::data(); DComplex* DComplexBandMat::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> FloatBandMat::dataVec(); RWMathVec<double> DoubleBandMat::dataVec(); RWMathVec<DComplex> DComplexBandMat::dataVec();
Returns the matrix's data vector, where the explicitly stored entries in the matrix are kept.
FloatBandMat FloatBandMat::deepCopy(); DoubleBandMat DoubleBandMat::deepCopy(); DComplexBandMat DComplexBandMat::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 FloatBandMat::deepenShallowCopy(); void DoubleBandMat::deepenShallowCopy(); void DComplexBandMat::deepenShallowCopy();
Ensures that the data in the matrix is not shared by any other matrix or vector. Also ensure that the stride in the data vector is equal to 1. If necessary, a new copy of the data vector is made.
RWMathVec<float> FloatBandMat::diagonal(int j=0); RWMathVec<double> DoubleBandMat::diagonal(int j=0); RWMathVec<DComplex> DComplexBandMat::diagonal(int j=0);
Returns a reference to the jth diagonal of the matrix. The main diagonal is indexed by 0, diagonals in the upper triangle are indexed with positive integers, and diagonals in the lower triangle are indexed with negative integers. Bounds checking is done if the preprocessor symbol BOUNDS_CHECK is defined when the header file is read. The member function bcdiagonal does the same thing with guaranteed bounds checking.
FloatBandMat FloatBandMat::leadingSubmatrix(int k); DoubleBandMat DoubleBandMat::leadingSubmatrix(int k); DComplexBandMat DComplexBandMat::leadingSubmatrix(int k);
Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.
unsigned FloatBandMat::lowerBandwidth(); unsigned DoubleBandMat::lowerBandwidth(); unsigned DComplexBandMat::lowerBandwidth();
Returns the lower bandwidth of the matrix.
void FloatBandMat::printOn(ostream&); void DoubleBandMat::printOn(ostream&); void DComplexBandMat::printOn(ostream&);
Prints the matrix to an output stream in human readable format.
ROFloatRef FloatBandMat::ref(int i, int j); RODoubleRef DoubleBandMat::ref(int i, int j); RODComplexRef DComplexBandMat::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.
FloatBandMat FloatBandMat::reference(FloatBandMat&); DoubleBandMat DoubleBandMat::reference(DoubleBandMat&); DComplexBandMat DComplexBandMat::reference(DComplexBandMat&);
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 DoubleBandMat::resize(unsigned n, unsigned n); void FloatBandMat::resize(unsigned n, unsigned n); void DComplexBandMat::resize(unsigned n, unsigned n); void DoubleBandMat::resize(unsigned n, unsigned n, unsigned lb,
unsigned ub); void FloatBandMat::resize(unsigned n, unsigned n, unsigned lb,
unsigned ub); void DComplexBandMat::resize(unsigned n, unsigned n, unsigned lb,
unsigned ub);
Resizes the matrix or changes both its size and lower and upper bandwidths. Any new entries in the matrix are set to 0.
void DoubleBandMat::restoreFrom(RWFile&); void FloatBandMat::restoreFrom(RWFile&); void DComplexBandMat::restoreFrom(RWFile&);
Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn member function.
void DoubleBandMat::restoreFrom(RWvistream&); void FloatBandMat::restoreFrom(RWvistream&); void DComplexBandMat::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 FloatBandMat::rows(); unsigned DoubleBandMat::rows(); unsigned DComplexBandMat::rows();
Returns the number of rows in the matrix.
void DoubleBandMat::saveOn(RWFile&); void FloatBandMat::saveOn(RWFile&); void DComplexBandMat::saveOn(RWFile&);
Stores a matrix to an RWFile. The matrix can be read using the restoreFrom member function.
void DoubleBandMat::saveOn(RWvostream&); void FloatBandMat::saveOn(RWvostream&); void DComplexBandMat::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 FloatBandMat::scanFrom(istream&); void DoubleBandMat::scanFrom(istream&); void DComplexBandMat::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: first the lower bandwidth, followed by the upper bandwidth, followed by the matrix itself. The sample matrix below shows the format. Note that extra white space and text preceding the bandwidth specification are ignored. Only the relevant band of the matrix is used.
2 1 5x5 [ 1 1 0 0 0 7 4 3 0 0 5 5 4 5 0 0 1 3 1 1 0 0 8 1 4 ]
void FloatBandMat::set(int i, int j, float x); void DoubleBandMat::set(int i, int j, double x); void DComplexBandMat::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.
unsigned FloatBandMat::upperBandwidth(); unsigned DoubleBandMat::upperBandwidth(); unsigned DComplexBandMat::upperBandwidth();
Returns the upper bandwidth of the matrix.
float FloatBandMat::val(int i, int j); double DoubleBandMat::val(int i, int j); DComplex DComplexBandMat::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.
FloatBandMat FloatBandMat::zero(); DoubleBandMat DoubleBandMat::zero(); DComplexBandMat DComplexBandMat::zero();
Sets every element of the matrix to 0.
RODoubleRef FloatBandMat::operator()(int i, int j); double FloatBandMat::operator()(int i, int j) const; ROFloatRef DoubleBandMat::operator()(int i, int j); float DoubleBandMat::operator()(int i, int j) const; RODComplexRef DComplexBandMat::operator()(int i, int j); DComplex DComplexBandMat::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 these cases, using this operator is equivalent to calling the ref member function. If the matrix is a const matrix, 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.
DoubleBandMat& operator=(const DoubleBandMat& A); FloatBandMat& operator=(const FloatBandMat& A); DComplexBandMat& operator=(const DComplexBandMat& 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, use the reference member function.
RWBoolean operator==(const DoubleBandMat& A); RWBoolean operator==(const FloatBandMat& A); RWBoolean operator==(const DComplexBandMat& A); RWBoolean operator!=(const DoubleBandMat& A); RWBoolean operator!=(const FloatBandMat& A); RWBoolean operator!=(const DComplexBandMat& 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 which are theoretically equal are not always numerically equal.
DoubleBandMat& operator*=(double x); FloatBandMat& operator*=(float x); DComplexBandMat& operator*=(DComplex x); DoubleBandMat& operator/=(double x); FloatBandMat& operator/=(float x); DComplexBandMat& operator/=(DComplex x);
Performs the indicated operation on each element of the matrix.
DoubleBandMat& operator+=(const DoubleBandMat& A); FloatBandMat& operator+=(const FloatBandMat& A); DComplexBandMat& operator+=(const DComplexBandMat& A); DoubleBandMat& operator-=(const DoubleBandMat& A); FloatBandMat& operator-=(const FloatBandMat& A); DComplexBandMat& operator-=(const DComplexBandMat& A); DoubleBandMat& operator*=(const DoubleBandMat& A); FloatBandMat& operator*=(const FloatBandMat& A); DComplexBandMat& operator*=(const DComplexBandMat& A); DoubleBandMat& operator/=(const DoubleBandMat& A); FloatBandMat& operator/=(const FloatBandMat& A); DComplexBandMat& operator/=(const DComplexBandMat& 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. You can use the product global function to do matrix-matrix inner product multiplication.
DoubleBandMat operator+(const DoubleBandMat&); FloatBandMat operator+(const FloatBandMat&); DComplexBandMat operator+(const DComplexBandMat&); DoubleBandMat operator-(const DoubleBandMat&); FloatBandMat operator-(const FloatBandMat&); DComplexBandMat operator-(const DComplexBandMat&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
DoubleBandMat operator+(const DoubleBandMat&,
const DoubleBandMat&); FloatBandMat operator+(const FloatBandMat&,
const FloatBandMat&); DComplexBandMat operator+(const DComplexBandMat&,
const DComplexBandMat&); DoubleBandMat operator-(const DoubleBandMat&,
const DoubleBandMat&); FloatBandMat operator-(const FloatBandMat&,
const FloatBandMat&); DComplexBandMat operator-(const DComplexBandMat&,
const DComplexBandMat&); DoubleBandMat operator*(const DoubleBandMat&,
const DoubleBandMat&); FloatBandMat operator*(const FloatBandMat&,
const FloatBandMat&); DComplexBandMat operator*(const DComplexBandMat&,
const DComplexBandMat&); DoubleBandMat operator/(const DoubleBandMat&,
const DoubleBandMat&); FloatBandMat operator/(const FloatBandMat&,
const FloatBandMat&); DComplexBandMat operator/(const DComplexBandMat&,
const DComplexBandMat&);
Performs element-by-element operations on the arguments. To do inner product matrix multiplication, use the product global function.
DoubleBandMat operator*(double,const DoubleBandMat&); DoubleBandMat operator*(const DoubleBandMat&,double); FloatBandMat operator*(float,const FloatBandMat&); FloatBandMat operator*(const FloatBandMat&,float); DComplexBandMat operator*(DComplex,const DComplexBandMat&); DComplexBandMat operator*(const DComplexBandMat&,DComplex); DoubleBandMat operator/(const DoubleBandMat&,double); FloatBandMat operator/(const FloatBandMat&,float); DComplexBandMat operator/(const DComplexBandMat&,DComplex);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s, const DoubleBandMat&); ostream& operator<<(ostream& s, const FloatBandMat&); ostream& operator<<(ostream& s, const DComplexBandMat&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s, const DoubleBandMat&); istream& operator>>(istream& s, const FloatBandMat&); istream& operator>>(istream& s, const DComplexBandMat&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
DoubleBandMat abs(const DoubleBandMat&); FloatBandMat abs(const FloatBandMat&); DoubleBandMat abs(const DComplexBandMat&);
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.
DoubleBandMat arg(const DComplexBandMat& A);
Returns a matrix where each element is the argument of the corresponding element in the matrix A.
DComplexBandMat conj(const DComplexBandMat& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
DComplexBandMat conjTransposeProduct(const DComplexBandMat& A,
const DComplexBandMat& B);
Returns the inner product (matrix product) of the complex conjugate transpose of A and the matrix B. This product is a banded matrix whose lower bandwidth is the sum of the upper bandwidth of A and the lower bandwidth of B, and whose upper bandwidth is the sum of the lower bandwidth of A and the upper bandwidth of B.
DoubleBandMat imag(const DComplexBandMat& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
double maxValue(const DoubleBandMat&); float maxValue(const FloatBandMat&); double minValue(const DoubleBandMat&); float minValue(const FloatBandMat&);
Returns the maximum or minimum entry in the matrix.
DoubleBandMat norm(const DComplexBandMat& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
DoubleBandMat product(const DoubleBandMat& A, const DoubleBandMat& B); FloatBandMat product(const FloatBandMat& A, const FloatBandMat& B); DComplexBandMat product(const DComplexBandMat& A, const DComplexBandMat& B);
Returns the inner product (matrix product) of A and B. This product is a banded matrix whose lower bandwidth is the sum of the lower bandwidths of A and B, and whose upper bandwidth is the sum of the upper bandwidths of A and B.
RWMathVec<double> product(const DoubleBandMat& A, const RWMathVec<double>& x); RWMathVec<float> product(const FloatBandMat& A, const RWMathVec<float>& x); RWMathVec<DComplex> product(const DComplexBandMat& A, const RWMathVec<DComplex>& x);
Returns the inner product (matrix-vector product) of A and x.
RWMathVec<double> product(const RWMathVec<double>& x, const DoubleBandMat& A); RWMathVec<float> product(const RWMathVec<float>& x, const FloatBandMat& A); RWMathVec<DComplex> product(const RWMathVec<DComplex>& x, const DComplexBandMat& A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
DoubleBandMat real(const DComplexBandMat& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
DoubleBandMat toBandMat(const RWGenMat<double>&, unsigned bl, unsigned bu); FloatBandMat toBandMat(const RWGenMat<float>&, unsigned bl, unsigned bu); DComplexBandMat toBandMat(const RWGenMat<DComplex>&, unsigned bl, unsigned bu);
Extracts a band of entries from a square matrix. The main diagonal is extracted, along with bl diagonals from the upper triangle of the matrix, and bl diagonals from the lower triangle of the matrix.
FloatBandMat toFloat(const DoubleBandMat&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
DComplexBandMat toHermBandMat(const DComplexBandMat& A);
Extracts the Hermitian part of a banded matrix. The Hermitian part of the banded matrix A is (A+conj(AT))/2.
DoubleSymBandMat toSymBandMat(const DoubleBandMat& A); FloatSymBandMat toSymBandMat(const FloatBandMat& A); DComplexSymBandMat toSymBandMat(const DComplexBandMat& A);
Extracts the symmetric part of a banded matrix. The symmetric part of the banded matrix A is (A+AT)/2.
DoubleTriDiagMat toTriDiagMat(const DoubleBandMat& A); FloatTriDiagMat toTriDiagMat(const FloatBandMat& A); DComplexTriDiagMat toTriDiagMat(const DComplexBandMat& A);
Extracts the tridiagonal part of a general banded matrix. The tridiagonal part of matrix A consists of the main diagonal, the subdiagonal, and the superdiagonal.
DoubleBandMat transpose(const DoubleBandMat&); FloatBandMat transpose(const FloatBandMat&); DComplexBandMat transpose(const DComplexBandMat&);
Returns the transpose of the argument matrix.
DoubleBandMat transposeProduct(const DoubleBandMat& A,
const DoubleBandMat& B); FloatBandMat transposeProduct(const FloatBandMat& A,
const FloatBandMat& B); DComplexBandMat transposeProduct(const DComplexBandMat& A, const DComplexBandMat& B);
Returns the inner product (matrix product) of the transpose of A and the matrix B. This product is a banded matrix whose lower bandwidth is the sum of the upper bandwidth of A and the lower bandwidth of B, and whose upper bandwidth is the sum of the lower bandwidth of A and the upper bandwidth of B.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.