>
>#include <rw/dtrdgmat.h> // DoubleTriDiagMat #include <rw/ftrdgmat.h> // FloatTriDiagMat #include <rw/ctrdgmat.h> // DComplexTriDiagMat DoubleTriDiagMat A;
The classes {TYPE}TriDiagMat encapsulate tridiagonal matrices. A tridiagonal matrix is nonzero only on the diagonal, the subdiagonal, and the superdiagonal. It is a banded matrix with upper and lower bandwidth equal to 1.
>>#include <rw/ftrdgmat.h> main() { FloatTriDiagMat T(5,5); T.diagonal() = 1; T.leadingSubmatrix(3).zero(); }
A tridiagonal matrix is nonzero only along the main diagonal, the subdiagonal, and the superdiagonal:
The matrix is stored in an analogous way to the banded matrix:
[ XXX A11 A21 A21 A22 A32 A23 A33 A43 A34 A44 A54 ... Ann XXX ]
The mapping between the array and storage vector is as follows:
>
DoubleTriDiagMat(); FloatTriDiagMat(); DComplexTriDiagMat();
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.
DoubleTriDiagMat(const DoubleTriDiagMat& A); FloatTriDiagMat(const FloatTriDiagMat& A); DComplexTriDiagMat(const DComplexTriDiagMat& 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.
DoubleTriDiagMat(unsigned n, unsigned n); FloatTriDiagMat(unsigned n, unsigned n); DComplexTriDiagMat(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.
DoubleTriDiagMat(const RWMathVec<double>& vd, unsigned n,
unsigned n); FloatTriDiagMat(const RWMathVec<float>& vd, unsigned n,
unsigned n); DComplexTriDiagMat(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.
DComplexTriDiagMat(const DoubleTriDiagMat& re); DComplexTriDiagMat(const DoubleTriDiagMat& re,
const DoubleTriDiagMat& im);
Constructs a complex matrix from the real and imaginary parts supplied. If no imaginary part is supplied, it is assumed to be 0.
DoubleTriDiagMat(const FloatTriDiagMat&);
Constructs a copy of the argument matrix with double precision entries.
unsigned FloatTriDiagMat::bandwidth(); unsigned DoubleTriDiagMat::bandwidth(); unsigned DComplexTriDiagMat::bandwidth();
Returns the bandwidth of the matrix. The bandwidth of a tridiagonal matrix is always 3.
ROFloatRef FloatTriDiagMat::bcref(int i, int j); RODoubleRef DoubleTriDiagMat::bcref(int i, int j); RODComplexRef DComplexTriDiagMat::bcref(int i, int j);
Returns a reference to the ijth element of the matrix, after doing bounds checking.
RWMathVec<float> FloatTriDiagMat::bcdiagonal(int j=0); RWMathVec<double> DoubleTriDiagMat::bcdiagonal(int j=0); RWMathVec<DComplex> DComplexTriDiagMat::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, the super diagonal by 1, and the subdiagonal by -1.
void FloatTriDiagMat::bcset(int i, int j, float x); void DoubleTriDiagMat::bcset(int i, int j, double x); void DComplexTriDiagMat::bcset(int i, int j, DComplex);
Sets the ijth element of the matrix equal to x, after doing bounds checking.
float FloatTriDiagMat::bcval(int i, int j); double DoubleTriDiagMat::bcval(int i, int j); DComplex DComplexTriDiagMat::bcval(int i, int j);
Returns the value of the ijth element of the matrix, after doing bounds checking.
unsigned FloatTriDiagMat::binaryStoreSize(); unsigned DoubleTriDiagMat::binaryStoreSize(); unsigned DComplexTriDiagMat::binaryStoreSize();
Returns the number of bytes that it would take to write the matrix to a file using saveOn.
unsigned FloatTriDiagMat::cols(); unsigned DoubleTriDiagMat::cols(); unsigned DComplexTriDiagMat::cols();
Returns the number of columns in the matrix.
FloatTriDiagMat FloatTriDiagMat::copy(); DoubleTriDiagMat DoubleTriDiagMat::copy(); DComplexTriDiagMat DComplexTriDiagMat::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* FloatTriDiagMat::data(); double* DoubleTriDiagMat::data(); DComplex* DComplexTriDiagMat::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> FloatTriDiagMat::dataVec(); RWMathVec<double> DoubleTriDiagMat::dataVec(); RWMathVec<DComplex> DComplexTriDiagMat::dataVec();
Returns the matrix's data vector. This is where the explicitly stored entries in the matrix are kept.
FloatTriDiagMat FloatTriDiagMat::deepCopy(); DoubleTriDiagMat DoubleTriDiagMat::deepCopy(); DComplexTriDiagMat DComplexTriDiagMat::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 FloatTriDiagMat::deepenShallowCopy(); void DoubleTriDiagMat::deepenShallowCopy(); void DComplexTriDiagMat::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> FloatTriDiagMat::diagonal(int j=0); RWMathVec<double> DoubleTriDiagMat::diagonal(int j=0); RWMathVec<DComplex> DComplexTriDiagMat::diagonal(int j=0);
Returns a reference to the jth diagonal of the matrix. The main diagonal is indexed by 0, the super diagonal by 1, and the subdiagonal by -1. 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.
unsigned FloatTriDiagMat::halfBandwidth(); unsigned DoubleTriDiagMat::halfBandwidth(); unsigned DComplexTriDiagMat::halfBandwidth();
Returns the half bandwidth of the matrix. The half bandwidth of a tridiagonal matrix is always 1.
FloatTriDiagMat FloatTriDiagMat::leadingSubmatrix(int k); DoubleTriDiagMat DoubleTriDiagMat::leadingSubmatrix(int k); DComplexTriDiagMat DComplexTriDiagMat::leadingSubmatrix(int k);
Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.
unsigned FloatTriDiagMat::lowerBandwidth(); unsigned DoubleTriDiagMat::lowerBandwidth(); unsigned DComplexTriDiagMat::lowerBandwidth();
Returns the lower bandwidth of the matrix. The lower bandwidth of a tridiagonal matrix is always 1.
void FloatTriDiagMat::printOn(ostream&); void DoubleTriDiagMat::printOn(ostream&); void DComplexTriDiagMat::printOn(ostream&);
Prints the matrix to an output stream in human readable format.
ROFloatRef FloatTriDiagMat::ref(int i, int j); RODoubleRef DoubleTriDiagMat::ref(int i, int j); RODComplexRef DComplexTriDiagMat::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.
FloatTriDiagMat FloatTriDiagMat::reference(FloatTriDiagMat&); DoubleTriDiagMat DoubleTriDiagMat::reference(DoubleTriDiagMat&); DComplexTriDiagMat DComplexTriDiagMat::reference(DComplexTriDiagMat&);
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 DoubleTriDiagMat::resize(unsigned n, unsigned n); void FloatTriDiagMat::resize(unsigned n, unsigned n); void DComplexTriDiagMat::resize(unsigned n, unsigned n);
Resizes the matrix. Any new entries in the matrix are set to 0. Both arguments must be the same.
void DoubleTriDiagMat::restoreFrom(RWFile&); void FloatTriDiagMat::restoreFrom(RWFile&); void DComplexTriDiagMat::restoreFrom(RWFile&);
Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn member function.
void DoubleTriDiagMat::restoreFrom(RWvistream&); void FloatTriDiagMat::restoreFrom(RWvistream&); void DComplexTriDiagMat::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 FloatTriDiagMat::rows(); unsigned DoubleTriDiagMat::rows(); unsigned DComplexTriDiagMat::rows();
Returns the number of rows in the matrix.
void DoubleTriDiagMat::saveOn(RWFile&); void FloatTriDiagMat::saveOn(RWFile&); void DComplexTriDiagMat::saveOn(RWFile&);
Stores a matrix to an RWFile. The matrix can be read using the restoreFrom member function.
void DoubleTriDiagMat::saveOn(RWvostream&); void FloatTriDiagMat::saveOn(RWvostream&); void DComplexTriDiagMat::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 FloatTriDiagMat::scanFrom(istream&); void DoubleTriDiagMat::scanFrom(istream&); void DComplexTriDiagMat::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 ignored. Only the main diagonal, subdiagonal, and superdiagonal part of the matrix are used.
4x4 [ 4 1 0 0 -5 9 2 0 0 -5 3 9 0 0 4 3 ]
void FloatTriDiagMat::set(int i, int j, float x); void DoubleTriDiagMat::set(int i, int j, double x); void DComplexTriDiagMat::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 FloatTriDiagMat::upperBandwidth(); unsigned DoubleTriDiagMat::upperBandwidth(); unsigned DComplexTriDiagMat::upperBandwidth();
Returns the upper bandwidth of the matrix. The upper bandwidth of a tridiagonal matrix is always 1.
float FloatTriDiagMat::val(int i, int j); double DoubleTriDiagMat::val(int i, int j); DComplex DComplexTriDiagMat::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.
FloatTriDiagMat FloatTriDiagMat::zero(); DoubleTriDiagMat DoubleTriDiagMat::zero(); DComplexTriDiagMat DComplexTriDiagMat::zero();
Sets every element of the matrix to 0.
RODoubleRefFloat TriDiagMat::operator()(int i, int j); double FloatTriDiagMat::operator()
(int i, int j) const; ROFloatRef DoubleTriDiagMat::operator()(int i, int j); float DoubleTriDiagMat::operator()(int i,
int j) const; RODComplexRef DComplexTriDiagMat::operator()(int i,
int j); DComplex DComplexTriDiagMat::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, 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.
DoubleTriDiagMat& operator=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator=(const DComplexTriDiagMat& 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.
DoubleTriDiagMat& operator==(const DoubleTriDiagMat& A); FloatTriDiagMat& operator==(const FloatTriDiagMat& A); DComplexTriDiagMat& operator==(const DComplexTriDiagMat& A); DoubleTriDiagMat& operator!=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator!=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator!=(const DComplexTriDiagMat& 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.
DoubleTriDiagMat& operator*=(double x); FloatTriDiagMat& operator*=(float x); DComplexTriDiagMat& operator*=(DComplex x); DoubleTriDiagMat& operator/=(double x); FloatTriDiagMat& operator/=(float x); DComplexTriDiagMat& operator/=(DComplex x);
Performs the indicated operation on each element of the matrix.
DoubleTriDiagMat& operator+=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator+=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator+=(const DComplexTriDiagMat& A); DoubleTriDiagMat& operator-=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator-=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator-=(const DComplexTriDiagMat& A); DoubleTriDiagMat& operator*=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator*=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator*=(const DComplexTriDiagMat& A); DoubleTriDiagMat& operator/=(const DoubleTriDiagMat& A); FloatTriDiagMat& operator/=(const FloatTriDiagMat& A); DComplexTriDiagMat& operator/=(const DComplexTriDiagMat& 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.
DoubleTriDiagMat operator+(const DoubleTriDiagMat&); FloatTriDiagMat operator+(const FloatTriDiagMat&); DComplexTriDiagMat operator+(const DComplexTriDiagMat&); DoubleTriDiagMat operator-(const DoubleTriDiagMat&); FloatTriDiagMat operator-(const FloatTriDiagMat&); DComplexTriDiagMat operator-(const DComplexTriDiagMat&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
DoubleTriDiagMat operator+(const DoubleTriDiagMat&,
const DoubleTriDiagMat&); FloatTriDiagMat operator+(const FloatTriDiagMat&,
const FloatTriDiagMat&); DComplexTriDiagMat operator+(const DComplexTriDiagMat&,
const DComplexTriDiagMat&); DoubleTriDiagMat operator-(const DoubleTriDiagMat&,
const DoubleTriDiagMat&); FloatTriDiagMat operator-(const FloatTriDiagMat&,
const FloatTriDiagMat&); DComplexTriDiagMat operator-(const DComplexTriDiagMat&,
const DComplexTriDiagMat&); DoubleTriDiagMat operator*(const DoubleTriDiagMat&,
const DoubleTriDiagMat&); FloatTriDiagMat operator*(const FloatTriDiagMat&,
const FloatTriDiagMat&); DComplexTriDiagMat operator*(const DComplexTriDiagMat&,
const DComplexTriDiagMat&); DoubleTriDiagMat operator/(const DoubleTriDiagMat&,
const DoubleTriDiagMat&); FloatTriDiagMat operator/(const FloatTriDiagMat&,
const FloatTriDiagMat&); DComplexTriDiagMat operator/(const DComplexTriDiagMat&,
const DComplexTriDiagMat&);
Performs element-by-element operations on the arguments. To do inner product matrix multiplication, use the product global function.
DoubleTriDiagMat operator*(double,const DoubleTriDiagMat&); DoubleTriDiagMat operator*(const DoubleTriDiagMat&,double); FloatTriDiagMat operator*(float,const FloatTriDiagMat&); FloatTriDiagMat operator*(const FloatTriDiagMat&,float); DComplexTriDiagMat operator*(DComplex,
const DComplexTriDiagMat&); DComplexTriDiagMat operator*(const DComplexTriDiagMat&,
DComplex); DoubleTriDiagMat operator/(const DoubleTriDiagMat&,double); FloatTriDiagMat operator/(const FloatTriDiagMat&,float); DComplexTriDiagMat operator/(const DComplexTriDiagMat&,
DComplex);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s, const DoubleTriDiagMat&); ostream& operator<<(ostream& s, const FloatTriDiagMat&); ostream& operator<<(ostream& s, const DComplexTriDiagMat&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s, const DoubleTriDiagMat&); istream& operator>>(istream& s, const FloatTriDiagMat&); istream& operator>>(istream& s, const DComplexTriDiagMat&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
DoubleTriDiagMat abs(const DoubleTriDiagMat&); FloatTriDiagMat abs(const FloatTriDiagMat&); DoubleTriDiagMat abs(const DComplexTriDiagMat&);
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.
DoubleTriDiagMat arg(const DComplexTriDiagMat& A);
Returns a matrix where each element is the argument of the corresponding element in the matrix A.
DComplexTriDiagMat conj(const DComplexTriDiagMat& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
DoubleTriDiagMat imag(const DComplexTriDiagMat& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
double maxValue(const DoubleTriDiagMat&); float maxValue(const FloatTriDiagMat&); double minValue(const DoubleTriDiagMat&); float minValue(const FloatTriDiagMat&);
Returns the maximum or minimum entry in the matrix.
DoubleTriDiagMat norm(const DComplexTriDiagMat& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
RWMathVec<double> product(const DoubleTriDiagMat& A,
const RWMathVec<double>& x); RWMathVec<float> product(const FloatTriDiagMat& A,
const RWMathVec<float>& x); RWMathVec<DComplex> product(const DComplexTriDiagMat& A, const RWMathVec<DComplex>& x);
Returns the inner product (matrix-vector product) of A and x.
RWMathVec<double> product(const RWMathVec<double>& x,
const DoubleTriDiagMat& A); RWMathVec<float> product(const RWMathVec<float>& x,
const FloatTriDiagMat& A); RWMathVec<DComplex> product(const RWMathVec<DComplex>& x, const DComplexTriDiagMat& A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
DoubleTriDiagMat real(const DComplexTriDiagMat& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
FloatTriDiagMat toFloat(const DoubleTriDiagMat&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
DoubleTriDiagMat toTriDiagMat(const RWGenMat<double>&); FloatTriDiagMat toTriDiagMat(const RWGenMat<float>&); DComplexTriDiagMat toTriDiagMat(const RWGenMat<DComplex>&);
Extracts the tridiagonal part of a square matrix. The tridiagonal part of a matrix A consists of the main diagonal, the subdiagonal, and the superdiagonal.
DoubleTriDiagMat transpose(const DoubleTriDiagMat&); FloatTriDiagMat transpose(const FloatTriDiagMat&); DComplexTriDiagMat transpose(const DComplexTriDiagMat&);
Returns the transpose of the argument matrix.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.