Module: Linear Algebra Group: Sparse Matrix classes
Does not inherit
abs() arg() conj() imag() maxValue() |
minValue() norm() operator>>() operator<<() operator*() |
operator+() operator-() operator/() product() real() |
toFloat() toTriDiagMat() transpose() |
#include <rw/lapack/trdgmat.h> RWTriDiagMat<double> A;
The class RWTriDiagMat<T> 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/lapack/trdgmat.h> int main() { RWTriDiagMat<float> T(5,5); T.diagonal() = 1; T.leadingSubmatrix(3).zero(); return 0; }
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. For convenience, there are some unused locations left in the vector of data. These are indicated as XXX in the following illustration of the storage vector:
[ 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:
RWTriDiagMat();
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.
RWTriDiagMat(const RWTriDiagMat<T>& 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.
RWTriDiagMat(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.
RWTriDiagMat(const RWMathVec<T>& data, 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.
RWTriDiagMat<DComplex>(const RWTriDiagMat<double>&
re); RWTriDiagMat<DComplex>(const RWTriDiagMat<double>&
re, const RWTriDiagMat<double>& im);
Constructs a complex matrix from the real and imaginary parts supplied. If no imaginary part is supplied, it is assumed to be 0.
RWTriDiagMat<double>(const RWTriDiagMat<float>&);
Constructs a copy of the argument matrix with double precision entries.
unsigned bandwidth();
Returns the bandwidth of the matrix. The bandwidth of a tridiagonal matrix is always 3.
RWRORef<T> bcref(int i, int j);
Returns a reference to the ijth element of the matrix, after doing bounds checking.
RWMathVec<T> 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, T x);
Sets the ijth element of the matrix equal to x, after doing bounds checking.
T bcval(int i, int j);
Returns the value of the ijth element of the matrix, after doing bounds checking.
unsigned binaryStoreSize();
Returns the number of bytes that it would take to write the matrix to a file using saveOn.
unsigned cols();
Returns the number of columns in the matrix.
RWTriDiagMat<T> 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.
T* 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<T> dataVec();
Returns the matrix's data vector. This is where the explicitly stored entries in the matrix are kept.
RWTriDiagMat<T> 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 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<T> 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 halfBandwidth();
Returns the half bandwidth of the matrix. The half bandwidth of a tridiagonal matrix is always 1.
RWTriDiagMat<T> leadingSubmatrix(int k);
Returns the k x k upper left corner of the matrix. The submatrix and the matrix share the same data.
unsigned lowerBandwidth();
Returns the lower bandwidth of the matrix. The lower bandwidth of a tridiagonal matrix is always 1.
void printOn(ostream&);
Prints the matrix to an output stream in human readable format.
RWRORef<T> 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.
RWTriDiagMat<T> reference(RWTriDiagMat<T>&);
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 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 restoreFrom(RWFile&);
Reads in a matrix from an RWFile. The matrix must have been stored to the file using the saveOn member function.
void 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 rows();
Returns the number of rows in the matrix.
void saveOn(RWFile&);
Stores a matrix to an RWFile. The matrix can be read using the restoreFrom member function.
void 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 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 set(int i, int j, T 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 upperBandwidth();
Returns the upper bandwidth of the matrix. The upper bandwidth of a tridiagonal matrix is always 1.
float 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.
RWTriDiagMat<T> zero();
Sets every element of the matrix to 0.
RWRORef<T>
RWTriDiagMat<T>::operator()(int i, int j); double
RWTriDiagMat<float>::operator()(int i, int j) const; ROFloatRef RWTriDiagMat<double>::operator()(int i, int j); float RWTriDiagMat<double>::operator()(int i, int j) const; RODComplexRef RWTriDiagMat<DComplex>::operator()(int i, int j); DComplex RWTriDiagMat<DComplex>::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.
RWTriDiagMat<T>& operator=(const RWTriDiagMat<T>&
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.
RWTriDiagMat<T>& operator==(const RWTriDiagMat<T>&
A); RWTriDiagMat<T>& operator!=(const RWTriDiagMat<T>&
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.
RWTriDiagMat<T>& operator*=(T x); RWTriDiagMat<T>& operator/=(T x);
Performs the indicated operation on each element of the matrix.
RWTriDiagMat<T>& operator+=(const RWTriDiagMat<T>&
A); RWTriDiagMat<T>& operator-=(const RWTriDiagMat<T>&
A); RWTriDiagMat<T>& operator*=(const RWTriDiagMat<T>&
A); RWTriDiagMat<T>& operator/=(const RWTriDiagMat<T>&
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.
RWTriDiagMat<T> operator+(const RWTriDiagMat<T>&); RWTriDiagMat<T> operator-(const RWTriDiagMat<T>&);
Unary plus and minus operators. Each operator returns a copy of the matrix or its negation.
RWTriDiagMat<T> operator+(const RWTriDiagMat<T>&,
const RWTriDiagMat<T>&); RWTriDiagMat<T> operator-(const RWTriDiagMat<T>&,
const RWTriDiagMat<T>&); RWTriDiagMat<T> operator*(const RWTriDiagMat<T>&,
const RWTriDiagMat<T>&); RWTriDiagMat<T> operator/(const RWTriDiagMat<T>&,
const RWTriDiagMat<T>&);
Performs element-by-element operations on the arguments. To do inner product matrix multiplication, use the product global function.
RWTriDiagMat<T> operator*(T,
const RWTriDiagMat<T>&); RWTriDiagMat<T> operator*(const RWTriDiagMat<T>&,
T); RWTriDiagMat<T> operator/(const RWTriDiagMat<T>&,
T);
Performs element-by-element operations on the arguments.
ostream& operator<<(ostream& s,
const RWTriDiagMat<T>&);
Writes the matrix to the stream. This is equivalent to calling the printOn member function.
istream& operator>>(istream& s,
const RWTriDiagMat<T>&);
Reads the matrix from the stream. This is equivalent to calling the scanFrom member function.
RWTriDiagMat<double> abs(const RWTriDiagMat<double>&); RWTriDiagMat<float> abs(const RWTriDiagMat<float>&); RWTriDiagMat<double> abs(const RWTriDiagMat<DComplex>&);
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.
RWTriDiagMat<double> arg(const RWTriDiagMat<DComplex>& A);
Returns a matrix where each element is the argument of the corresponding element in the matrix A.
RWTriDiagMat<DComplex> conj(const RWTriDiagMat<DComplex>& A);
Returns a matrix where each element is the complex conjugate of the corresponding element in the matrix A.
RWTriDiagMat<double> imag(const RWTriDiagMat<DComplex>& A);
Returns a matrix where each element is the imaginary part of the corresponding element in the matrix A.
double maxValue(const RWTriDiagMat<double>&); float maxValue(const RWTriDiagMat<float>&); double minValue(const RWTriDiagMat<double>&); float minValue(const RWTriDiagMat<float>&);
Returns the maximum or minimum entry in the matrix.
RWTriDiagMat<double> norm(const RWTriDiagMat<DComplex>& A);
Returns a matrix where each element is the norm (magnitude) of the corresponding element in the matrix A.
RWMathVec<T> product(const RWTriDiagMat<T>& A,
const RWMathVec<T>& x);
Returns the inner product (matrix-vector product) of A and x.
RWMathVec<T> product(const RWMathVec<T>& x,
const RWTriDiagMat<T>& A);
Returns the inner product (matrix-vector product) of x and A. This is equal to the product of A transpose and x.
RWTriDiagMat<double> real(const RWTriDiagMat<DComplex>& A);
Returns a matrix where each element is the real part of the corresponding element in the matrix A.
RWTriDiagMat<float> toFloat(const RWTriDiagMat<double>&);
Converts a matrix from double to float precision. The conversion is done using a constructor.
RWTriDiagMat<T> toTriDiagMat(const RWGenMat<T>&);
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.
RWTriDiagMat<T> transpose(const RWTriDiagMat<T>&);
Returns the transpose of the argument matrix.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.