CVM Class Library  8.1
This C++ class library encapsulates concepts of vector and different matrices including square, band, symmetric and hermitian ones in Euclidean space of real and complex numbers.
 All Classes Files Functions Variables Typedefs Friends Macros Pages
Public Member Functions | Friends | List of all members
basic_rmatrix< TR > Class Template Reference

End-user class encapsulating matrix of real numbers. More...

#include <cvm.h>

Inheritance diagram for basic_rmatrix< TR >:
Inheritance graph
[legend]
Collaboration diagram for basic_rmatrix< TR >:
Collaboration graph
[legend]

Public Member Functions

 basic_rmatrix ()
 Default constructor.
 basic_rmatrix (tint nM, tint nN)
 Constructor.
 basic_rmatrix (TR *pd, tint nM, tint nN)
 Constructor.
 basic_rmatrix (const TR *pd, tint nM, tint nN)
 Constructor.
 basic_rmatrix (const basic_rmatrix &m)
 Copy constructor.
 basic_rmatrix (basic_rmatrix &&m) noexcept
 Move constructor.
 basic_rmatrix (const RVector &v, bool bBeColumn=true)
 Constructor.
 basic_rmatrix (basic_rmatrix &m, tint nRow, tint nCol, tint nHeight, tint nWidth)
 Submatrix constructor.
type_proxy< TR, TR > operator() (tint nRow, tint nCol) throw (cvmexception)
 Reference to element (l-value)
TR operator() (tint nRow, tint nCol) const throw (cvmexception)
 Value of element (not l-value)
RVector operator() (tint nCol) throw (cvmexception)
 Column as l-value.
RVector operator[] (tint nRow) throw (cvmexception)
 Row as l-value.
const RVector operator() (tint nCol) const throw (cvmexception)
 Column as not l-value.
const RVector operator[] (tint nRow) const throw (cvmexception)
 Row as not l-value.
RVector diag (tint nDiag) throw (cvmexception)
 Diagonal as l-value.
const RVector diag (tint nDiag) const throw (cvmexception)
 Diagonal (not l-value)
basic_rmatrixoperator= (const basic_rmatrix &m) throw (cvmexception)
 Assignment operator.
basic_rmatrixoperator= (basic_rmatrix &&m) throw (cvmexception)
 Move assignment operator.
basic_rmatrixassign (const RVector &v) throw (cvmexception)
 Vector (as array) assignment.
basic_rmatrixassign (const TR *pd)
 External array assignment.
basic_rmatrixassign (tint nRow, tint nCol, const basic_rmatrix &m) throw (cvmexception)
 Assignment to submatrix.
basic_rmatrixset (TR d)
 Sets all elements to one value.
basic_rmatrixresize (tint nNewM, tint nNewN) throw (cvmexception)
 Changes dimensions.
bool operator== (const basic_rmatrix &m) const
 Matrix comparison.
bool operator!= (const basic_rmatrix &m) const
 Matrix comparison.
basic_rmatrixoperator<< (const basic_rmatrix &m) throw (cvmexception)
 Matrix replacement.
basic_rmatrix operator+ (const basic_rmatrix &m) const throw (cvmexception)
 Addition operator.
basic_rmatrix operator- (const basic_rmatrix &m) const throw (cvmexception)
 Subtraction operator.
basic_rmatrixsum (const basic_rmatrix &m1, const basic_rmatrix &m2) throw (cvmexception)
 Sum of matrices.
basic_rmatrixdiff (const basic_rmatrix &m1, const basic_rmatrix &m2) throw (cvmexception)
 Difference of matrices.
basic_rmatrixoperator+= (const basic_rmatrix &m) throw (cvmexception)
 Increment operator.
basic_rmatrixoperator-= (const basic_rmatrix &m) throw (cvmexception)
 Decrement operator.
basic_rmatrix operator- () const
 Unary minus operator.
basic_rmatrix operator* (TR dMult) const
 Multiply by number operator.
basic_rmatrix operator/ (TR dDiv) const throw (cvmexception)
 Divide by number operator.
basic_rmatrixoperator*= (TR dMult)
 Multiply by number and assign.
basic_rmatrixoperator/= (TR dDiv) throw (cvmexception)
 Divide by number and assign.
basic_rmatrixnormalize ()
 Matrix normalizer.
basic_rmatrix operator~ () const throw (cvmexception)
 Matrix transposition.
basic_rmatrixtranspose (const basic_rmatrix &m) throw (cvmexception)
 Matrix transposition.
basic_rmatrixtranspose () throw (cvmexception)
 Matrix transposition (in-place)
RVector operator* (const RVector &v) const throw (cvmexception)
 Matrix-vector product.
basic_rmatrix operator* (const basic_rmatrix &m) const throw (cvmexception)
 Matrix-matrix product.
basic_rmatrixmult (const basic_rmatrix &m1, const basic_rmatrix &m2) throw (cvmexception)
 Matrix-matrix product.
basic_rmatrixrank1update (const RVector &vCol, const RVector &vRow) throw (cvmexception)
 Rank-1 update.
basic_rmatrixswap_rows (tint n1, tint n2) throw (cvmexception)
 Rows swap.
basic_rmatrixswap_cols (tint n1, tint n2) throw (cvmexception)
 Columns swap.
basic_rmatrixsolve (const basic_srmatrix< TR > &mA, const basic_rmatrix &mB, TR &dErr) throw (cvmexception)
 Linear solver.
basic_rmatrixsolve_tran (const basic_srmatrix< TR > &mA, const basic_rmatrix &mB, TR &dErr) throw (cvmexception)
 Linear solver (transposed)
basic_rmatrixsolve (const basic_srmatrix< TR > &mA, const basic_rmatrix &mB) throw (cvmexception)
 Linear solver.
basic_rmatrixsolve_tran (const basic_srmatrix< TR > &mA, const basic_rmatrix &mB) throw (cvmexception)
 Linear solver (transposed)
basic_rmatrixsolve_lu (const basic_srmatrix< TR > &mA, const basic_srmatrix< TR > &mLU, const tint *pPivots, const basic_rmatrix &mB, TR &dErr) throw (cvmexception)
 LU factorization based linear solver.
basic_rmatrixsolve_lu (const basic_srmatrix< TR > &mA, const basic_srmatrix< TR > &mLU, const tint *pPivots, const basic_rmatrix &mB) throw (cvmexception)
 LU factorization based linear solver.
RVector svd () const throw (cvmexception)
 Singular value decomposition.
RVector svd (basic_srmatrix< TR > &mU, basic_srmatrix< TR > &mVH) const throw (cvmexception)
 Singular value decomposition.
basic_rmatrix pinv (TR threshold=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Pseudo (generalized) inversion.
basic_rmatrixpinv (const basic_rmatrix &mA, TR threshold=basic_cvmMachSp< TR >()) throw (cvmexception)
 Pseudo (generalized) inversion.
basic_rmatrix gels (bool transpose, const basic_rmatrix &mB, basic_rvector< TR > &vErr) const throw (cvmexception)
 Overdetermined or underdetermined linear solver.
basic_rmatrixgels (bool transpose, const basic_rmatrix &mA, const basic_rmatrix &mB, basic_rvector< TR > &vErr) throw (cvmexception)
 Overdetermined or underdetermined linear solver.
basic_rvector< TR > gels (bool transpose, const basic_rvector< TR > &vB, TR &dErr) const throw (cvmexception)
 Overdetermined or underdetermined linear solver.
basic_rmatrix gelsy (const basic_rmatrix &mB, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
basic_rmatrixgelsy (const basic_rmatrix &mA, const basic_rmatrix &mB, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvector< TR > gelsy (const basic_rvector< TR > &vB, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
basic_rmatrix gelss (const basic_rmatrix &mB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
basic_rmatrixgelss (const basic_rmatrix &mA, const basic_rmatrix &mB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvector< TR > gelss (const basic_rvector< TR > &vB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
basic_rmatrix gelsd (const basic_rmatrix &mB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
basic_rmatrixgelsd (const basic_rmatrix &mA, const basic_rmatrix &mB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvector< TR > gelsd (const basic_rvector< TR > &vB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Linear least squares problem.
tint rank (TR tol=basic_cvmMachSp< TR >()) const throw (cvmexception)
 Matrix rank.
void qr (basic_rmatrix< TR > &mQ, basic_srmatrix< TR > &mR) const throw (cvmexception)
 QR factorization ("economy" mode)
void qr (basic_srmatrix< TR > &mQ, basic_rmatrix< TR > &mR) const throw (cvmexception)
 QR factorization ("full" mode)
void lq (basic_srmatrix< TR > &mL, basic_rmatrix< TR > &mQ) const throw (cvmexception)
 LQ factorization ("economy" mode)
void lq (basic_rmatrix< TR > &mL, basic_srmatrix< TR > &mQ) const throw (cvmexception)
 LQ factorization ("full" mode)
void rq (basic_srmatrix< TR > &mR, basic_rmatrix< TR > &mQ) const throw (cvmexception)
 RQ factorization ("economy" mode)
void rq (basic_rmatrix< TR > &mR, basic_srmatrix< TR > &mQ) const throw (cvmexception)
 RQ factorization ("full" mode)
void ql (basic_rmatrix< TR > &mQ, basic_srmatrix< TR > &mL) const throw (cvmexception)
 QL factorization ("economy" mode)
void ql (basic_srmatrix< TR > &mQ, basic_rmatrix< TR > &mL) const throw (cvmexception)
 QL factorization ("full" mode)
basic_rmatrixger (TR alpha, const RVector &vCol, const RVector &vRow) throw (cvmexception)
 Rank-1 update matrix-vector operation.
basic_rmatrixgemm (const basic_rmatrix &m1, bool bTrans1, const basic_rmatrix &m2, bool bTrans2, TR dAlpha, TR dBeta) throw (cvmexception)
 Generic matrix-matrix operation.
basic_rmatrixsymm (bool bLeft, const basic_srsmatrix< TR > &ms, const basic_rmatrix &m, TR dAlpha, TR dBeta) throw (cvmexception)
 Generic symmetric matrix-matrix operation.
basic_rmatrixvanish ()
 Set matrix to zero.
basic_rmatrixrandomize (TR dFrom, TR dTo)
 Randomizer.
TR norm2 () const override
 2-norm
- Public Member Functions inherited from Matrix< TR, TR >
tint msize () const
 Number of rows.
tint nsize () const
 Number of columns.
tint ld () const
 Leading dimension.
tint rowofmax () const
 Row with maximum element.
tint rowofmin () const
 Row with minimum element.
tint colofmax () const
 Column with maximum element.
tint colofmin () const
 Column with minimum element.
TR norm1 () const override
 1-norm
TR norminf () const override
 Infinity norm.
- Public Member Functions inherited from basic_array< TR, TR >
 basic_array ()
 Default constructor.
 basic_array (tint nSize, bool bZeroMemory=true)
 Constructor.
 basic_array (TR *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TR *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_array (const TR *begin, const TR *end)
 Constructor.
 basic_array (const basic_array &a)
 Copy constructor.
 basic_array (basic_array &&a) noexcept
 Move constructor.
basic_arrayoperator= (const basic_array &a) throw (cvmexception)
 Assignment operator.
basic_arrayoperator= (basic_array &&a) throw (cvmexception)
 Move assignment operator.
virtual ~basic_array ()
 Destructor.
tint size () const
 Size (length) of array.
TR * get ()
 Pointer to data.
const TR * get () const
 Const pointer to data.
 operator TR * ()
 operator const TR * () const
void assign (size_type n, const TR &val) throw (cvmexception)
 (STL) assigns given value to n-th element (0-based)
void assign (const_iterator begin, const_iterator end) throw (cvmexception)
 (STL) assigns begin-end iteartor range to array
basic_arrayresize (tint nNewSize) throw (cvmexception)
 Changes size of array.
tint incr () const
 Increment between elements.
tint indofmax () const
 Index of element with maximum module.
tint indofmin () const
 Index of element with minimum module.
virtual TR norm () const
 Euclidean norm.
iterator begin ()
 (STL) iterator to begin
const_iterator begin () const
 (STL) const iterator to begin
iterator end ()
 (STL) iterator to end
const_iterator end () const
 (STL) const iterator to end
reverse_iterator rbegin ()
 (STL) iterator to begin reversed
const_reverse_iterator rbegin () const
 (STL) const iterator to begin reversed
reverse_iterator rend ()
 (STL) iterator to end reversed
const_reverse_iterator rend () const
 (STL) const iterator to end reversed
size_type max_size () const
 (STL) maximum possible size of array
size_type capacity () const
 (STL) current capacity of array, equal to size()
bool empty () const
 (STL) is array empty
reference front ()
 (STL) reference to first element
const_reference front () const
 (STL) const reference to first element
reference back ()
 (STL) reference to last element
const_reference back () const
 (STL) const reference to last element
void clear ()
 (STL) clears array, dealocates memory and sets size() to zero
void swap (basic_array &v) throw (cvmexception)
 (STL) swaps array values, throws cvmexception if sizes are different
reference at (size_type n) throw (cvmexception)
 (STL) returns reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
const_reference at (size_type n) const throw (cvmexception)
 (STL) returns const reference to n-th element of array (0-based), throws cvmexception if n is out of boundaries
void push_back (const TR &x) throw (cvmexception)
 (STL) pushes new value to the end of array
void pop_back () throw (cvmexception)
 (STL) removes last element from array
iterator insert (iterator position, const TR &x) throw (cvmexception)
 (STL) inserts element to given position in array
iterator erase (iterator position) throw (cvmexception)
 (STL) removes element from given position in array

Friends

class basic_rvector< TR >

Additional Inherited Members

- Public Types inherited from basic_array< TR, TR >
typedef TR value_type
 STL-specific value type definition.
typedef value_typepointer
 STL-specific value pointer definition.
typedef value_typeiterator
 STL-specific iterator definition.
typedef const value_typeconst_iterator
 STL-specific const iterator definition.
typedef const value_typeconst_pointer
 STL-specific const pointer definition.
typedef value_typereference
 STL-specific reference definition.
typedef const value_typeconst_reference
 STL-specific const reference definition.
typedef size_t size_type
 STL-specific size type definition.
typedef ptrdiff_t difference_type
 STL-specific difference type definition.
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
 STL-specific const reverse iterator definition.
typedef std::reverse_iterator
< iterator
reverse_iterator
 STL-specific reverse iterator definition.
- Protected Member Functions inherited from Matrix< TR, TR >
 Matrix ()
 Default constructor.
 Matrix (tint nM, tint nN, tint nLD, bool bZeroMemory)
 Constructor.
 Matrix (TR *pd, tint nM, tint nN, tint nLD, tint nSize)
 Constructor.
 Matrix (const TR *pd, tint nM, tint nN, tint nLD, tint nSize)
 Constructor.
 Matrix (const BaseArray &v, bool bBeColumn)
 Constructor.
 Matrix (Matrix &&m) noexcept
 Move constructor.
Matrixoperator= (Matrix &&m) throw (cvmexception)
 Move assignment operator.
- Protected Attributes inherited from Matrix< TR, TR >
tint mm
 Number of rows.
tint mn
 Number of columns.
tint mld
 Leading dimension.

Detailed Description

template<typename TR>
class basic_rmatrix< TR >

End-user class encapsulating matrix of real numbers.

TR type stands for treal. Please use predefined rmatrix class in your applications.

See Also
Matrix

Definition at line 10717 of file cvm.h.

Constructor & Destructor Documentation

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( )
inline

Default constructor.

Creates empty matrix. No memory gets allocated.

Example:
using namespace cvm;
std::cout << m.msize() << std::endl << m.nsize() << std::endl;
std::cout << m.size() << std::endl;
m.resize (2, 3);
std::cout << m;
prints
0
0
0
0 0 0
0 0 0

Definition at line 10749 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( tint  nM,
tint  nN 
)
inline

Constructor.

Creates $m\times n$ rmatrix object where $m$ is passed in nM parameter (number of rows) and $n$ is passed in nN (number of columns). Constructor sets all elements to zero. It throws cvmexception in case of non-positive sizes passed or memory allocation failure. Example:

using namespace cvm;
rmatrix m (3, 4);
std::cout << m.msize() << std::endl << m.nsize()
<< std::endl << m.size() << std::endl << m;

prints

3
4
12
0 0 0 0
0 0 0 0
0 0 0 0
Parameters
[in]nMNumber of rows.
[in]nNNumber of columns.

Definition at line 10779 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( TR *  pd,
tint  nM,
tint  nN 
)
inline

Constructor.

Creates $m\times n$ rmatrix object where $m$ is passed in nM parameter (number of rows) and $n$ is passed in nN (number of columns). It throws cvmexception in case of non-positive sizes passed. Unlike others, this constructor does not allocate memory. It just shares memory with array pointed to by pd (for matrices nIncr=1 is always satisfied).

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m (a, 2, 3);
m(1,1) = 7.77;
std::cout << m << std::endl;
std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;
prints
7.77e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
7.77e+000 2.00e+000 3.00e+000
See Also
http://cvmlib.com/faq.htm
basic_rvector::basic_rvector(TR*,tint,tint)
Parameters
[in]pdPointer to array to share memory with.
[in]nMNumber of rows.
[in]nNNumber of columns.

Definition at line 10816 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( const TR *  pd,
tint  nM,
tint  nN 
)
inline

Constructor.

Creates $m\times n$ rmatrix object where $m$ is passed in nM parameter (number of rows) and $n$ is passed in nN (number of columns). Constructor throws cvmexception in case of non-positive sizes passed. This is const version, it allocates memory and copies every element (deep copy) from external array pointed to by pd parameter. It copies nM*nN elements total. Example:

using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
const double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m (a, 2, 3);
m(1,1) = 7.77;
std::cout << m << std::endl;
std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;

prints

7.77e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
1.00e+000 2.00e+000 3.00e+000
See Also
http://cvmlib.com/faq.htm
basic_rvector::basic_rvector(const TR*,tint,tint)
Parameters
[in]pdConst pointer to external array.
[in]nMNumber of rows.
[in]nNNumber of columns.

Definition at line 10855 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( const basic_rmatrix< TR > &  m)
inline

Copy constructor.

Creates rmatrix object as a copy of matrix m. It throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m (a, 2, 3);
rmatrix mc(m);
m(1,1) = 7.77;
std::cout << m << std::endl << mc;
prints
7.77e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
1.00e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
Parameters
[in]mrmatrix to copy from.

Definition at line 10887 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( basic_rmatrix< TR > &&  m)
inline

Move constructor.

Implements move semantics introduced in new C++ standard. Moves data ownership from other matrix to newly created object. It's usually executed implicitly in cases like this:

rvector a(b + c);

or this

rvector a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to newly created object a.

Parameters
[in]mrvalue reference to other matrix.

Definition at line 10910 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( const RVector v,
bool  bBeColumn = true 
)
inlineexplicit

Constructor.

Creates rmatrix object containing v.size() rows and 1 column if bBeColumn is true or 1 row and v.size() columns otherwise. After that it copies elements of vector v to the matrix created. Constructor throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v(3);
v(1) = 1.;
v(2) = 2.;
v(3) = 3.;
rmatrix mc (v);
rmatrix mr (v, false);
std::cout << mc << std::endl << mr;
prints
1.00e+000
2.00e+000
3.00e+000
1.00e+000 2.00e+000 3.00e+000
Parameters
[in]vrvector to copy elements from.
[in]bBeColumnTrue to create column matrix.

Definition at line 10949 of file cvm.h.

template<typename TR>
basic_rmatrix< TR >::basic_rmatrix ( basic_rmatrix< TR > &  m,
tint  nRow,
tint  nCol,
tint  nHeight,
tint  nWidth 
)
inline

Submatrix constructor.

Creates rmatrix object as submatrix of matrix m. It means that the matrix object created shares memory with some part of m. This part is defined by its upper left corner (parameters nRow and nCol, both are CVM0 based) and its height and width (parameters nHeight and nWidth).

Example:
using namespace cvm;
rmatrix m(4,5);
rmatrix subm(m, 2, 2, 2, 2);
subm.set(1.);
std::cout << m;
prints
0 0 0 0 0
0 1 1 0 0
0 1 1 0 0
0 0 0 0 0
Parameters
[in]mParent rmatrix to attach to.
[in]nRowRow to start from (CVM0 based).
[in]nColColumn to start from (CVM0 based).
[in]nHeightNumber of submatrix's rows.
[in]nWidthNumber of submatrix's columns.

Definition at line 10984 of file cvm.h.

Member Function Documentation

template<typename TR>
type_proxy<TR,TR> basic_rmatrix< TR >::operator() ( tint  nRow,
tint  nCol 
) throw (cvmexception)
inline

Reference to element (l-value)

Operator provides access to a particular element of calling matrix by its row and column index. Indexes passed are CVM0 based. It returns l-value in order to make possible write access to an element. Operator throws cvmexception if nRow or nCol is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
rmatrix ms(m);
std::cout << m(1,1) << " " << m(2,3) << std::endl << std::endl;
ms(2,2) = 7.77;
std::cout << ms;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+00 6.00e+00
1.00e+00 3.00e+00 5.00e+00
2.00e+00 7.77e+00 6.00e+00
See Also
http://cvmlib.com/faq.htm
Parameters
[in]nRowRow index (CVM0 based).
[in]nColColumn index (CVM0 based).
Returns
type_proxy Proxy to element (l-value).

Reimplemented in basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11028 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
TR basic_rmatrix< TR >::operator() ( tint  nRow,
tint  nCol 
) const throw (cvmexception)
inline

Value of element (not l-value)

Operator returns value of a particular element of calling matrix by its row and column index. Indexes passed are CVM0 based. Operator throws cvmexception if nRow or nCol is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
std::cout << m(1,1) << " " << m(2,3) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+00 6.00e+00
See Also
http://cvmlib.com/faq.htm
Parameters
[in]nRowRow index (CVM0 based).
[in]nColColumn index (CVM0 based).
Returns
TR treal value.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11065 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::operator() ( tint  nCol) throw (cvmexception)
inline

Column as l-value.

Operator provides access to nCol-th column (CVM0 based) of calling matrix by returning rvector sharing memory with it. Operator throws cvmexception if nCol is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
srmatrix ms(2);
std::cout << m(2) << std::endl;
ms(2) = m(3);
std::cout << ms;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.00e+00 4.00e+00
0.00e+00 5.00e+00
0.00e+00 6.00e+00
Parameters
[in]nColIndex of column (CVM0 based).
Returns
rvector Column as l-value.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srmatrix< TR >.

Definition at line 11107 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::operator[] ( tint  nRow) throw (cvmexception)
inline

Row as l-value.

Operator provides access to nRow-th row (CVM0 based) of calling matrix by returning rvector sharing memory with it. Operator throws cvmexception if nRow is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
srmatrix ms(3);
std::cout << m[1] << std::endl;
ms[1] = m[2];
std::cout << ms;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+00 3.00e+00 5.00e+00
2.00e+00 4.00e+00 6.00e+00
0.00e+00 0.00e+00 0.00e+00
0.00e+00 0.00e+00 0.00e+00
Parameters
[in]nRowIndex of row (CVM0 based).
Returns
rvector Row as l-value.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srmatrix< TR >.

Definition at line 11149 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
const RVector basic_rmatrix< TR >::operator() ( tint  nCol) const throw (cvmexception)
inline

Column as not l-value.

Operator creates rvector object as a copy of nCol-th column (CVM0 based) of calling matrix. Operator throws cvmexception if nCol is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
std::cout << m(2) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.00e+00 4.00e+00
Parameters
[in]nColIndex of column (CVM0 based).
Returns
rvector Column value.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11181 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
const RVector basic_rmatrix< TR >::operator[] ( tint  nRow) const throw (cvmexception)
inline

Row as not l-value.

Operator creates rvector object as a copy of nRow-th row (CVM0 based) of calling matrix. Operator throws cvmexception if nRow is outside of boundaries.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m (a, 2, 3);
std::cout << m[1] << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+00 3.00e+00 5.00e+00
Parameters
[in]nRowIndex of row (CVM0 based).
Returns
rvector Row value.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11213 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::diag ( tint  nDiag) throw (cvmexception)
inline

Diagonal as l-value.

Operator provides access to nDiag-th diagonal of calling matrix (here nDiag=0 for main diagonal, nDiag<0 for lower diagonals and nDiag>0 for upper ones) by returning rvector sharing memory with it. Operator throws cvmexception if nDiag is outside of boundaries.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
rmatrix m(2,3);
m.diag(-1).set(1.);
m.diag(0).set(2.);
m.diag(1).set(3.);
m.diag(2).set(4.);
std::cout << m << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
2 3 4
1 2 3
Parameters
[in]nDiagIndex of diagonal (0 for main diagonal, negative for lower, positive for upper one).
Returns
rvector Diagonal as l-value.

Definition at line 11252 of file cvm.h.

template<typename TR>
const RVector basic_rmatrix< TR >::diag ( tint  nDiag) const throw (cvmexception)
inline

Diagonal (not l-value)

Operator creates rvector object as a copy of nDiag-th diagonal of calling matrix where nDiag=0 for main diagonal, nDiag<0 for lower diagonals and nDiag>0 for upper ones. Operator throws cvmexception if nDiag is outside of boundaries.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
const rmatrix ms(a,3,3);
std::cout << ms << std::endl;
std::cout << ms.diag(0) << ms.diag(1);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 4 7
2 5 8
3 6 9
1 5 9
4 8
Parameters
[in]nDiagIndex of diagonal (0 for main diagonal, negative for lower, positive for upper one).
Returns
rvector Diagonal value.

Reimplemented in basic_srsmatrix< TR >.

Definition at line 11288 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator= ( const basic_rmatrix< TR > &  m) throw (cvmexception)
inline

Assignment operator.

Sets every element of calling rmatrix to be equal to appropriate element of matrix m and returns reference to the matrix changed. Operator throws cvmexception in case of different matrix dimensions.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m1(a, 3, 2);
rmatrix m2(3, 2);
m2 = m1;
std::cout << m2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+000 4.00e+000
2.00e+000 5.00e+000
3.00e+000 6.00e+000
Parameters
[in]mrmatrix to assign from.
Returns
Reference to changed calling matrix.

Definition at line 11325 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator= ( basic_rmatrix< TR > &&  m) throw (cvmexception)
inline

Move assignment operator.

Implements move semantics introduced in new C++ standard. Moves data ownership from other matrix to calling object. It's usually executed implicitly in cases like this:

a = b + c;

Here temporary result of calling b.operator+(c) will not be destroyed but rather moved to calling object a.

Parameters
[in]mrvalue reference to other matrix.

Definition at line 11346 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::assign ( const RVector v) throw (cvmexception)
inline

Vector (as array) assignment.

Sets every element of calling matrix to be equal to appropriate element of rvector v as an array. Assignment is performed according to matrix storage (by columns). It's assumed that vector passed is long enough to fill calling matrix. Function throws cvmexception otherwise.

Example:
try {
const double a[] = {1., 2., 3., 4., 5., 6., 7., 8.};
const rvector v(a,8);
rmatrix m(2,3);
std::cout << v << std::endl;
m.assign(v);
std::cout << m;
} catch (std::exception& e) {
std::cout << "Exception: " << e.what () << std::endl;
}
prints
1 2 3 4 5 6 7 8
1 3 5
2 4 6
Parameters
[in]vrvector to assign.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11382 of file cvm.h.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::assign ( const TR *  pd)
inline

External array assignment.

Sets every element of calling matrix to be equal to appropriate element of array pointed to by parameter pd and returns reference to the matrix changed. Assignment is performed according to matrix storage (by columns). It's assumed that array passed is long enough to fill calling matrix.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
const double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(2, 3);
m.assign(a);
std::cout << m;
prints
1.00e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
Parameters
[in]pdConst pointer to external array.
Returns
Reference to changed calling matrix.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11416 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::assign ( tint  nRow,
tint  nCol,
const basic_rmatrix< TR > &  m 
) throw (cvmexception)
inline

Assignment to submatrix.

Sets submatrix of calling matrix beginning with row nRow and column nCol to matrix m and returns reference to the matrix changed. Function throws cvmexception if nRow or nCol are not positive or matrix m doesn't fit. Indexes are CVM0 based.

Example:
using namespace cvm;
rmatrix m1(4,5);
rmatrix m2(2,2);
m1.set(1.);
m2.set(2.);
m1.assign(2,3,m2);
std::cout << m1;
prints
1 1 1 1 1
1 1 2 2 1
1 1 2 2 1
1 1 1 1 1
Parameters
[in]nRowRow index (CVM0 based).
[in]nColColumn index (CVM0 based).
[in]mReference to matrix to assign.
Returns
Reference to changed calling matrix.

Definition at line 11452 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::set ( TR  d)
inline

Sets all elements to one value.

Sets every element of calling matrix to be equal to parameter d and returns reference to the matrix changed.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rmatrix m(2, 3);
m.set(3.);
std::cout << m;
prints
3.00e+000 3.00e+000 3.00e+000
3.00e+000 3.00e+000 3.00e+000
Parameters
[in]dValue to set to.
Returns
Reference to changed calling matrix.

Reimplemented from basic_array< TR, TR >.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11484 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::resize ( tint  nNewM,
tint  nNewN 
) throw (cvmexception)
inline

Changes dimensions.

Changes dimensions of calling matrix to to nNewM by nNewN and returns reference to the matrix changed. In case of increasing of its size, the matrix is filled up with zeroes. Function throws cvmexception in case of negative dimension passed or memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
std::cout << m << std::endl;
m.resize (2, 2);
std::cout << m << std::endl;
m.resize (3, 3);
std::cout << m;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+000 3.00e+000 5.00e+000
2.00e+000 4.00e+000 6.00e+000
1.00e+000 3.00e+000
2.00e+000 4.00e+000
1.00e+000 3.00e+000 0.00e+000
2.00e+000 4.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000
Parameters
[in]nNewMNew number of rows.
[in]nNewNNew number of columns.
Returns
Reference to changed calling matrix.

Definition at line 11533 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
bool basic_rmatrix< TR >::operator== ( const basic_rmatrix< TR > &  m) const
inline

Matrix comparison.

Operator compares calling matrix with matrix m and returns true if they have same sizes and their appropriate elements differ by not more than cvmMachMin() (the smallest normalized positive number). Returns false otherwise.

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4.};
rmatrix m1(a, 2, 2);
rmatrix m2(2, 2);
m2(1,1) = 1.; m2(1,2) = 3.;
m2(2,1) = 2.; m2(2,2) = 4.;
std::cout << (m1 == m2) << std::endl;
prints
1
See Also
operator !=()
Parameters
[in]mrmatrix to compare to.
Returns
bool Result of comparison.

Definition at line 11565 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
bool basic_rmatrix< TR >::operator!= ( const basic_rmatrix< TR > &  m) const
inline

Matrix comparison.

Operator compares calling matrix with matrix m and returns true if they have different sizes or at least one of their appropriate elements differs by more than cvmMachMin() (the smallest normalized positive number). Returns false otherwise.

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4.};
rmatrix m1(a, 2, 2);
rmatrix m2(2, 2);
m2(1,1) = 1.; m2(1,2) = 3.;
m2(2,1) = 2.; m2(2,2) = 4.;
std::cout << (m1 != m2) << std::endl;
prints
0
See Also
operator ==()
Parameters
[in]mrmatrix to compare to.
Returns
bool Result of comparison.

Definition at line 11595 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator<< ( const basic_rmatrix< TR > &  m) throw (cvmexception)
inline

Matrix replacement.

Destroys calling matrix, creates a new one as a copy of m and returns reference to the matrix changed. Operator throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rmatrix m(3,4);
rmatrix mc(1,1);
m(1,2) = 1.;
m(3,4) = 2.;
std::cout << m << mc << std::endl;
mc << m;
std::cout << mc;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
0.00e+000 1.00e+000 0.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000 2.00e+000
0.00e+000
0.00e+000 1.00e+000 0.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000 2.00e+000
See Also
operator =()
Parameters
[in]mrmatrix to replace by.
Returns
Reference to changed calling matrix.

Definition at line 11639 of file cvm.h.

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator+ ( const basic_rmatrix< TR > &  m) const throw (cvmexception)
inline

Addition operator.

Creates object of type rmatrix as sum of calling matrix and matrix m. Operator throws cvmexception in case of different sizes of the operands or memory allocation failure.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix ma(a,2,3);
rmatrix mb(2,3);
mb.set(1.);
std::cout << ma + mb << std::endl;
std::cout << ma + ma;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
2 4 6
3 5 7
2 6 10
4 8 12
See Also
sum()
Parameters
[in]mrmatrix to add to calling one.
Returns
Result object as sum of matrices.

Definition at line 11682 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator- ( const basic_rmatrix< TR > &  m) const throw (cvmexception)
inline

Subtraction operator.

Creates object of type rmatrix as difference of calling matrix and matrix m. It throws cvmexception in case of different sizes of the operands or memory allocation failure.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix ma(a,2,3);
rmatrix mb(2,3);
mb.set(1.);
std::cout << ma - mb << std::endl;
std::cout << ma - ma;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
0 2 4
1 3 5
0 0 0
0 0 0
See Also
diff()
Parameters
[in]mrmatrix to subtract from calling one.
Returns
Result object as difference of matrices.

Definition at line 11726 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::sum ( const basic_rmatrix< TR > &  m1,
const basic_rmatrix< TR > &  m2 
) throw (cvmexception)
inline

Sum of matrices.

Assigns sum of matrices m1 and m2 to calling matrix and returns reference to the matrices changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m1(a, 2, 3);
rmatrix m2(2, 3);
rmatrix m(2, 3);
m2.set(1.);
std::cout << m.sum(m1, m2) << std::endl;
std::cout << m.sum(m, m2);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
2 4 6
3 5 7
3 5 7
4 6 8
See Also
operator +()
Parameters
[in]m1First rmatrix summand.
[in]m2Second rmatrix summand.
Returns
Reference to changed calling matrix.

Definition at line 11771 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::diff ( const basic_rmatrix< TR > &  m1,
const basic_rmatrix< TR > &  m2 
) throw (cvmexception)
inline

Difference of matrices.

Assigns difference of matrices m1 and m2 to calling matrix and returns reference to the matrix changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix m1(a, 2, 3);
rmatrix m2(2, 3);
rmatrix m(2, 3);
m2.set(1.);
std::cout << m.diff(m1, m2) << std::endl;
std::cout << m.diff(m, m2);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
0 2 4
1 3 5
-1 1 3
0 2 4
See Also
operator -()
Parameters
[in]m1First rmatrix subtrahend.
[in]m2Second rmatrix subtrahend.
Returns
Reference to changed calling matrix.

Definition at line 11817 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator+= ( const basic_rmatrix< TR > &  m) throw (cvmexception)
inline

Increment operator.

Adds matrix m to calling matrix and returns reference to the matrix changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
try {
rmatrix m1(2, 3);
rmatrix m2(2, 3);
m1.set(1.);
m2.set(2.);
m1 += m2;
std::cout << m1 << std::endl;
// well, you can do this too, but temporary object would be created
m2 += m2;
std::cout << m2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3 3 3
3 3 3
4 4 4
4 4 4
See Also
operator +()
sum()
Parameters
[in]mrmatrix to increment by.
Returns
Reference to changed calling matrix.

Definition at line 11866 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator-= ( const basic_rmatrix< TR > &  m) throw (cvmexception)
inline

Decrement operator.

Subtracts matrix m from calling matrix and returns reference to the matrix changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
try {
rmatrix m1(2, 3);
rmatrix m2(2, 3);
m1.set(1.);
m2.set(2.);
m1 -= m2;
std::cout << m1 << std::endl;
// well, you can do this too, but temporary object would be created
m2 -= m2;
std::cout << m2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1 -1 -1
-1 -1 -1
0 0 0
0 0 0
See Also
operator -()
diff()
Parameters
[in]mrmatrix to decrement by.
Returns
Reference to changed calling matrix.

Definition at line 11913 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator- ( ) const
inline

Unary minus operator.

Creates object of type rmatrix as calling matrix multiplied by -1. It throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4., 5., 6.};
const rmatrix ma(a, 2, 3);
std::cout << - ma;
prints
-1 -3 -5
-2 -4 -6
Returns
Result object.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11941 of file cvm.h.

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator* ( TR  dMult) const
inline

Multiply by number operator.

Creates object of type rmatrix as product of calling matrix and number dMult. It throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
std::cout << m * 2.;
prints
2 6 10
4 8 12
See Also
operator *=()
Parameters
[in]dMultNumber to multiply by.
Returns
Result object.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 11970 of file cvm.h.

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator/ ( TR  dDiv) const throw (cvmexception)
inline

Divide by number operator.

Creates object of type rmatrix as quotient of calling matrix and number dDiv. It throws cvmexception if dDiv has absolute value equal or less than cvmMachMin() (the smallest normalized positive number). It also throws exception in case of memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
std::cout << m / 2.;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
5.00e-01 1.50e+00 2.50e+00
1.00e+00 2.00e+00 3.00e+00
See Also
operator /=()
Parameters
[in]dDivNumber to divide by.
Returns
Result object.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12008 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator*= ( TR  dMult)
inline

Multiply by number and assign.

Multiplies calling matrix by number dMult and returns reference to the matrix changed.

Example:
using namespace cvm;
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
m *= 2.;
std::cout << m;
prints
2 6 10
4 8 12
See Also
operator *(TR) const
Parameters
[in]dMultNumber to multiply by.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12037 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::operator/= ( TR  dDiv) throw (cvmexception)
inline

Divide by number and assign.

Divides calling matrix by number dDiv and returns reference to the matrix changed. It throws cvmexception if dDiv has absolute value equal or less than cvmMachMin() (the smallest normalized positive number).

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
m /= 2.;
std::cout << m;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
5.00e-01 1.50e+00 2.50e+00
1.00e+00 2.00e+00 3.00e+00
See Also
operator /(TR) const
Parameters
[in]dDivNumber to divide by.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12075 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::normalize ( )
inline

Matrix normalizer.

Normalizes calling matrix so its Euclidean norm() becomes equal to 1 if it was greater than cvmMachMin() (the smallest normalized positive number) before the call. Does nothing otherwise.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a, 2, 3);
m.normalize();
std::cout << m << m.norm() << std::endl;
prints
1.05e-01 3.14e-01 5.24e-01
2.10e-01 4.19e-01 6.29e-01
1
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12106 of file cvm.h.

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator~ ( ) const throw (cvmexception)
inline

Matrix transposition.

Creates object of type rmatrix as transposed calling matrix.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a,2,3);
std::cout << m << std::endl << ~m;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 3 5
2 4 6
1 2
3 4
5 6
Returns
Result object.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12139 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::transpose ( const basic_rmatrix< TR > &  m) throw (cvmexception)
inline

Matrix transposition.

Sets calling matrix to be equal to matrix m transposed. Function throws cvmexception in case of not appropriate sizes of the operands.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a,2,3);
rmatrix mt(3,2);
std::cout << m << std::endl;
mt.transpose(m);
std::cout << mt;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 3 5
2 4 6
1 2
3 4
5 6
Parameters
[in]mrmatrix to transpose.
Returns
Reference to changed calling matrix.

Definition at line 12178 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::transpose ( ) throw (cvmexception)
inline

Matrix transposition (in-place)

Makes calling matrix to be equal to transposed itself. Function throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m(a,2,3);
std::cout << m << std::endl;
std::cout << m.transpose();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 3 5
2 4 6
1 2
3 4
5 6
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12220 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::operator* ( const RVector v) const throw (cvmexception)
inline

Matrix-vector product.

Creates object of type rvector as product of calling matrix and vector v. Function throws cvmexception if the number of columns of the calling matrix differs from size of the vector v. Use basic_rvector::mult(const basic_rmatrix<TR>&,const basic_rvector<TR>&) to avoid new object creation.

Example:
using namespace cvm;
try {
rmatrix m(2, 3);
rvector v(3);
m.set(1.);
v.set(1.);
std::cout << m * v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3 3
See Also
basic_rvector::mult(const basic_rmatrix<TR>&,const basic_rvector<TR>&)
Parameters
[in]vrvector to compute product with.
Returns
Result object.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 12257 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::operator* ( const basic_rmatrix< TR > &  m) const throw (cvmexception)
inline

Matrix-matrix product.

Creates object of type rmatrix as product of calling matrix and matrix m. Operator throws cvmexception if number of columns of calling matrix differs from number of rows of the matrix m. Use mult() to avoid new object creation.

Example:
using namespace cvm;
try {
rmatrix m1(2, 3);
rmatrix m2(3, 2);
m1.set(1.);
m2.set(1.);
std::cout << m1 * m2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3 3
3 3
Parameters
[in]mrmatrix to compute product with.
Returns
Result object.

Definition at line 12294 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::mult ( const basic_rmatrix< TR > &  m1,
const basic_rmatrix< TR > &  m2 
) throw (cvmexception)
inline

Matrix-matrix product.

Sets calling matrix to be equal to product of matrix m1 by matrix m2 and returns reference to the matrix changed. Function throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
try {
rmatrix m1(2, 3);
rmatrix m2(3, 2);
rmatrix m(2, 2);
m1.set(1.);
m2.set(1.);
std::cout << m.mult(m1, m2) << std::endl;
std::cout << m1.mult(m, m1);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3 3
3 3
6 6 6
6 6 6
Parameters
[in]m1rmatrix multiplicand.
[in]m2rmatrix multiplier.
Returns
Reference to changed calling matrix.

Definition at line 12336 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::rank1update ( const RVector vCol,
const RVector vRow 
) throw (cvmexception)
inline

Rank-1 update.

Sets calling matrix to be a rank-1 update of vectors vCol and vRow. Function throws cvmexception if number of rows of calling matrix is not equal to size of vCol or number of columns of calling matrix is not equal to size of vRow. The rank-1 update of vector-column $x$ of size $m$ and vector-row $y$ of size $n$ is defined as $m\times n$ matrix

\[\begin{pmatrix} x_1 y_1 & x_1 y_2 & \cdots & x_1 y_n \\ x_2 y_1 & x_2 y_2 & \cdots & x_2 y_n \\ \hdotsfor{4} \\ x_m y_1 & x_m y_2 & \cdots & x_m y_n \end{pmatrix} = \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_m \end{pmatrix} \begin{pmatrix} y_1 & y_2 & \cdots & y_n \end{pmatrix}.\]

Example:
using namespace cvm;
try {
rvector vc(3), vr(2);
rmatrix m(3, 2);
vc(1) = 1.;
vc(2) = 2.;
vc(3) = 3.;
vr(1) = 4.;
vr(2) = 5.;
std::cout << m.rank1update (vc, vr);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
4 5
8 10
12 15
Parameters
[in]vColColumn rvector.
[in]vRowRow rvector.
Returns
Reference to changed calling matrix.

Definition at line 12394 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::swap_rows ( tint  n1,
tint  n2 
) throw (cvmexception)
inline

Rows swap.

Swaps two rows of calling matrix and returns reference to the matrix changed. n1 and n2 are indexes of rows to be swapped, both are CVM0 based. Function throws cvmexception if one of the parameters is outside of boundaries.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m (a, 3, 2);
std::cout << m << std::endl;
std::cout << m.swap_rows(2,3);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 4
2 5
3 6
1 4
3 6
2 5
Parameters
[in]n1Row index to swap.
[in]n2Row index to swap.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srmatrix< TR >.

Definition at line 12438 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::swap_cols ( tint  n1,
tint  n2 
) throw (cvmexception)
inline

Columns swap.

Swaps two columnss of calling matrix and returns reference to the matrix changed. n1 and n2 are indexes of columns to be swapped, both are CVM0 based. Function throws cvmexception if one of the parameters is outside of boundaries.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.};
rmatrix m (a, 2, 3);
std::cout << m << std::endl;
std::cout << m.swap_cols(2,3);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 3 5
2 4 6
1 5 3
2 6 4
Parameters
[in]n1Column index to swap.
[in]n2Column index to swap.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srmatrix< TR >.

Definition at line 12475 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve ( const basic_srmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
TR &  dErr 
) throw (cvmexception)
inline

Linear solver.

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A*X=B$ where parameter mA is square matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. It also sets output parameter dErr to be equal to the norm of computation error. Function throws cvmexception in case of inappropriate sizes of the operands or when the matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (2);
try {
srmatrix ma(3);
rmatrix mb(3,4);
rmatrix mx(3,4);
double dErr;
ma.randomize(-10., 10.);
mb.randomize(-10., 10.);
mx.solve (ma, mb, dErr);
std::cout << ma * mx - mb << dErr << std::endl;
}
catch (cvmexception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.78e-015 +1.80e-016 -8.88e-016 +0.00e+000
+0.00e+000 -1.33e-015 +8.88e-016 +0.00e+000
+0.00e+000 +0.00e+000 -1.78e-015 +0.00e+000
+2.02e-015
See Also
solve(const basic_srmatrix<TR>&,const basic_rmatrix<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]mBrmatrix $B$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling matrix.

Definition at line 12522 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve_tran ( const basic_srmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
TR &  dErr 
) throw (cvmexception)
inline

Linear solver (transposed)

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A^T*X=B$ (which is equivalent to $X^T*A=B^T$) where parameter mA is square matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. It also sets output parameter dErr to be equal to the norm of computation error. Function throws cvmexception in case of inappropriate sizes of the operands or when the matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (2);
try {
srmatrix ma(3);
rmatrix mb(3,4);
rmatrix mx(3,4);
double dErr;
ma.randomize(-10., 10.);
mb.randomize(-10., 10.);
mx.solve_tran (ma, mb, dErr);
std::cout << ~ma * mx - mb << dErr << std::endl;
std::cout << ~mx * ma - ~mb;
}
catch (cvmexception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.776e-015 -8.882e-016 -3.553e-015 +4.441e-016
+0.000e+000 +3.553e-015 +1.243e-014 -8.882e-016
+0.000e+000 +3.553e-015 -1.066e-014 +0.000e+000
+4.357e-015
-1.776e-015 +0.000e+000 +0.000e+000
-8.882e-016 +3.553e-015 +3.553e-015
-3.553e-015 +1.243e-014 -1.066e-014
+4.441e-016 -8.882e-016 +0.000e+000
See Also
solve_tran(const basic_srmatrix<TR>&,const basic_rmatrix<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]mBrmatrix $B$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling matrix.

Definition at line 12574 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve ( const basic_srmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB 
) throw (cvmexception)
inline

Linear solver.

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A*X=B$ where parameter mA is square matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. Function throws cvmexception in case of inappropriate sizes of the operands or when the matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (2);
try {
srmatrix ma(3);
rmatrix mb(3,4);
rmatrix mx(3,4);
ma.randomize(-10., 10.);
mb.randomize(-10., 10.);
mx.solve (ma, mb);
std::cout << ma * mx - mb;
}
catch (cvmexception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.78e-015 +1.80e-016 -8.88e-016 +0.00e+000
+0.00e+000 -1.33e-015 +8.88e-016 +0.00e+000
+0.00e+000 +0.00e+000 -1.78e-015 +0.00e+000
See Also
solve(const basic_srmatrix<TR>&,const basic_rmatrix<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]mBrmatrix $B$.
Returns
Reference to changed calling matrix.

Definition at line 12615 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve_tran ( const basic_srmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB 
) throw (cvmexception)
inline

Linear solver (transposed)

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A^T*X=B$ (which is equivalent to $X^T*A=B^T$) where parameter mA is square matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. Function throws cvmexception in case of inappropriate sizes of the operands or when the matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (2);
try {
srmatrix ma(3);
rmatrix mb(3,4);
rmatrix mx(3,4);
ma.randomize(-10., 10.);
mb.randomize(-10., 10.);
mx.solve_tran (ma, mb);
std::cout << ~ma * mx - mb << std::endl;
std::cout << ~mx * ma - ~mb;
}
catch (cvmexception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.776e-015 -8.882e-016 -3.553e-015 +4.441e-016
+0.000e+000 +3.553e-015 +1.243e-014 -8.882e-016
+0.000e+000 +3.553e-015 -1.066e-014 +0.000e+000
-1.776e-015 +0.000e+000 +0.000e+000
-8.882e-016 +3.553e-015 +3.553e-015
-3.553e-015 +1.243e-014 -1.066e-014
+4.441e-016 -8.882e-016 +0.000e+000
See Also
solve_tran(const basic_srmatrix<TR>&,const basic_rmatrix<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]mBrmatrix $B$.
Returns
Reference to changed calling matrix.

Definition at line 12666 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve_lu ( const basic_srmatrix< TR > &  mA,
const basic_srmatrix< TR > &  mLU,
const tint pPivots,
const basic_rmatrix< TR > &  mB,
TR &  dErr 
) throw (cvmexception)
inline

LU factorization based linear solver.

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A*X=B$ where parameter mA is square matrix $A$, parameter mLU is LU factorization (see srmatrix::low_up() ) of matrix $A$, parameter pPivots is an array of pivot numbers created while factorizing matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. It also sets output parameter dErr to be equal to the norm of computation error. This function is useful when you need to solve few linear equations of kind $A*X=B$ with the same matrix $A$ and different matrices $B$. In such case you save on matrix $A$ factorization since it's needed to be performed just one time. Throws cvmexception in case of inappropriate sizes of the objects or when matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
srmatrix ma(a,3);
srmatrix mLU(3);
rmatrix mb1(3,2);
rmatrix mb2(3,2);
rmatrix mx1(3,2);
rmatrix mx2(3,2);
iarray nPivots(3);
double dErr = 0.;
mb1.randomize(-1.,3.);
mb2.randomize(2.,5.);
mLU.low_up(ma, nPivots);
std::cout << mx1.solve_lu (ma, mLU, nPivots, mb1, dErr);
std::cout << dErr << std::endl;
std::cout << mx2.solve_lu (ma, mLU, nPivots, mb2) << std::endl;
std::cout << ma * mx1 - mb1 << std::endl << ma * mx2 - mb2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.85e+00 5.90e-01
-4.23e+00 -3.67e+00
2.10e+00 2.55e+00
7.04e-15
9.49e+00 8.93e+00
-1.00e+01 -1.42e+01
4.21e+00 7.55e+00
0.00e+00 0.00e+00
0.00e+00 0.00e+00
4.44e-16 -1.11e-16
4.44e-16 0.00e+00
-4.44e-16 0.00e+00
8.88e-16 0.00e+00
See Also
srmatrix::low_up()
Parameters
[in]mAsrmatrix $A$.
[in]mLULU factorization of matrix $A$.
[in]pPivotspivots vector.
[in]mBrmatrix $B$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling matrix.

Definition at line 12741 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::solve_lu ( const basic_srmatrix< TR > &  mA,
const basic_srmatrix< TR > &  mLU,
const tint pPivots,
const basic_rmatrix< TR > &  mB 
) throw (cvmexception)
inline

LU factorization based linear solver.

Sets calling matrix to be equal to solution $X$ of matrix linear equation $A*X=B$ where parameter mA is square matrix $A$, parameter mLU is LU factorization (see srmatrix::low_up() ) of matrix $A$, parameter pPivots is an array of pivot numbers created while factorizing matrix $A$ and parameter mB is matrix $B$. Function returns reference to the matrix changed. This function is useful when you need to solve few linear equations of kind $A*X=B$ with the same matrix $A$ and different matrices $B$. In such case you save on matrix $A$ factorization since it's needed to be performed just one time. Throws cvmexception in case of inappropriate sizes of the objects or when matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
srmatrix ma(a,3);
srmatrix mLU(3);
rmatrix mb1(3,2);
rmatrix mb2(3,2);
rmatrix mx1(3,2);
rmatrix mx2(3,2);
iarray nPivots(3);
mb1.randomize(-1.,3.);
mb2.randomize(2.,5.);
mLU.low_up(ma, nPivots);
std::cout << mx1.solve_lu (ma, mLU, nPivots, mb1);
std::cout << std::endl;
std::cout << mx2.solve_lu (ma, mLU, nPivots, mb2) << std::endl;
std::cout << ma * mx1 - mb1 << std::endl << ma * mx2 - mb2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.85e+00 5.90e-01
-4.23e+00 -3.67e+00
2.10e+00 2.55e+00
9.49e+00 8.93e+00
-1.00e+01 -1.42e+01
4.21e+00 7.55e+00
0.00e+00 0.00e+00
0.00e+00 0.00e+00
4.44e-16 -1.11e-16
4.44e-16 0.00e+00
-4.44e-16 0.00e+00
8.88e-16 0.00e+00
See Also
srmatrix::low_up()
Parameters
[in]mAsrmatrix $A$.
[in]mLULU factorization of matrix $A$.
[in]pPivotspivots vector.
[in]mBrmatrix $B$.
Returns
Reference to changed calling matrix.

Definition at line 12818 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::svd ( ) const throw (cvmexception)
inline

Singular value decomposition.

Creates rvector of singular values

\[ \sigma_1\ge\sigma_2\ge\dots\ge\sigma_{\min(m,n)}\ge 0 \]

of $m\times n$ real matrix $A$ (calling matrix). These values are the main diagonal of matrix $\Sigma$ of the singular value decomposition

\[ A=U\Sigma V^H \]

where $U$ and $V$ are orthogonal for real $A$ and unitary for complex $A$. $V^H$ is transposed $V$ for real one and hermitian conjugated $V$ for complex one. First $\min(m, n)$ columns of matrices $U$ and $V$ are left and right singular vectors of $A$ respectively. Singular values and singular vectors satisfy

\[ Av_i=\sigma_i u_i\ \ \text{ and }\ \ A^Hu_i=\sigma_i v_i \]

where $u_i$ and $v_i$ are $i$-th columns of $U$ and $V$ respectively. Function throws cvmexception in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (5);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
std::cout << mA.svd();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
4.95615e+000 2.50884e+000 3.77219e-001
Returns
Result object (singular values in decreasing order).

Definition at line 12867 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
RVector basic_rmatrix< TR >::svd ( basic_srmatrix< TR > &  mU,
basic_srmatrix< TR > &  mVH 
) const throw (cvmexception)
inline

Singular value decomposition.

Creates rvector of singular values

\[ \sigma_1\ge\sigma_2\ge\dots\ge\sigma_{\min(m,n)}\ge 0 \]

of $m\times n$ real matrix $A$ (calling matrix). These values are the main diagonal of matrix $\Sigma$ of the singular value decomposition

\[ A=U\Sigma V^H \]

where $U$ and $V$ are orthogonal for real $A$ and unitary for complex $A$. $V^H$ is transposed $V$ for real one and hermitian conjugated $V$ for complex one. First $\min(m, n)$ columns of matrices $U$ and $V$ are left and right singular vectors of $A$ respectively. Singular values and singular vectors satisfy

\[ Av_i=\sigma_i u_i\ \ \text{ and }\ \ A^Hu_i=\sigma_i v_i \]

where $u_i$ and $v_i$ are $i$-th columns of $U$ and $V$ respectively. Function sets output parameter mU to be equal to square matrix $U$ of size $m\times m$ and mVH to be equal to square matrix $V^H$ of size $n\times n$. Function throws cvmexception in case of inappropriate calling object size (it must be equal to $\min(m,n)$), matrix mU size (must be $m\times m$), matrix mVH size (must be $n\times n$) or in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
rmatrix mSigma(4,3);
srmatrix mU(4), mVH(3);
v << mA.svd(mU, mVH);
mSigma.diag(0) = v;
std::cout << mU << std::endl;
std::cout << mVH << std::endl;
std::cout << mSigma << std::endl;
std::cout << (mA * ~mVH - mU * mSigma).norm() << std::endl;
std::cout << (~mA * mU - ~(mSigma * mVH)).norm() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-4.84e-01 1.95e-01 1.15e-02 -8.53e-01
2.17e-01 -3.41e-01 -8.89e-01 -2.13e-01
6.62e-01 7.16e-01 -6.18e-02 -2.13e-01
-5.29e-01 5.78e-01 -4.53e-01 4.26e-01
-2.21e-01 8.54e-01 -4.72e-01
9.59e-01 1.04e-01 -2.62e-01
-1.75e-01 -5.11e-01 -8.42e-01
4.96e+00 0.00e+00 0.00e+00
0.00e+00 2.51e+00 0.00e+00
0.00e+00 0.00e+00 3.77e-01
0.00e+00 0.00e+00 0.00e+00
1.37e-15
2.48e-15
Parameters
[out]mUsrmatrix $U$.
[out]mVHsrmatrix $V^H$.
Returns
Result object (singular values in decreasing order).

Definition at line 12949 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::pinv ( TR  threshold = basic_cvmMachSp<TR>()) const throw (cvmexception)
inline

Pseudo (generalized) inversion.

Creates object of type rmatrix as pseudo inverted calling matrix. Matrix pseudo inversion (aka Moore-Penrose generalized inversion) definition: $n\times m$ matrix $A^{+}$ is pseudo inversion of $m\times n$ matrix $A$ if the following two equations are satisfied:

\[ AA^{+}A=A,\quad A^{+}=QA^H=A^HP \]

where $Q$ and $P$ are some matrices. To compute the pseudo inversion, we use singular value decomposition

\[ A = U\Sigma V^H \]

of matrix $A$, thus

\[ A^{+} = V\Sigma^{-1}U^{H}, \]

where $\Sigma^{-1}$ is diagonal $n\times m$ matrix having inverted diagonal values of matrix $\Sigma$ if they are greater than some threshold, and zeros otherwise. The threshold parameter sets minimum distinguishable from zero singular value to be used to compute the pseudo inversion. All values equal or less than the threshold are treated as zeros. Function throws cvmexception in case of memory allocation failure.

Example:
using namespace cvm;
try {
rmatrix mA(3,4);
mA(1,1) = 1.; mA(1,2) = -1.; mA(1,3) = 2.; mA(1,4) = 0.;
mA(2,1) = -1.; mA(2,2) = 2.; mA(2,3) = -3.; mA(2,4) = 1.;
mA(3,1) = 0.; mA(3,2) = 1.; mA(3,3) = -1.; mA(3,4) = 1.;
rmatrix mX = mA.pinv(1.e-13);
std::cout << mX << (mA * mX * mA - mA).norm2() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+3.3333333e-001 -2.1510571e-016 +3.3333333e-001
+1.1111111e-001 +1.1111111e-001 +2.2222222e-001
+2.2222222e-001 -1.1111111e-001 +1.1111111e-001
+4.4444444e-001 +1.1111111e-001 +5.5555556e-001
+2.5460202e-015
See Also
svd()
Parameters
[in]thresholdAlgorithm threshold.
Returns
Result object.

Definition at line 13009 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::pinv ( const basic_rmatrix< TR > &  mA,
TR  threshold = basic_cvmMachSp<TR>() 
) throw (cvmexception)
inline

Pseudo (generalized) inversion.

Sets calling matrix to be equal to matrix mA pseudo inverted. Matrix pseudo inversion (aka Moore-Penrose generalized inversion) definition: $n\times m$ matrix $A^{+}$ is pseudo inversion of $m\times n$ matrix $A$ if the following two equations are satisfied:

\[ AA^{+}A=A,\quad A^{+}=QA^H=A^HP \]

where $Q$ and $P$ are some matrices. To compute the pseudo inversion, we use singular value decomposition

\[ A = U\Sigma V^H \]

of matrix $A$, thus

\[ A^{+} = V\Sigma^{-1}U^{H}, \]

where $\Sigma^{-1}$ is diagonal $n\times m$ matrix having inverted diagonal values of matrix $\Sigma$ if they are greater than some threshold, and zeros otherwise. The threshold parameter sets minimum distinguishable from zero singular value to be used to compute the pseudo inversion. All values equal or less than the threshold are treated as zeros. Function throws cvmexception in case of not appropriate sizes of the operands.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (3);
try {
rmatrix mA(3,4);
rmatrix mX(4,3);
mA(1,1) = 1.; mA(1,2) = -1.; mA(1,3) = 2.; mA(1,4) = 0.;
mA(2,1) = -1.; mA(2,2) = 2.; mA(2,3) = -3.; mA(2,4) = 1.;
mA(3,1) = 0.; mA(3,2) = 1.; mA(3,3) = -1.; mA(3,4) = 1.;
mX.pinv(mA, 1.e-13);
std::cout << mX << (mA * mX * mA - mA).norm2() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+3.333e-001 -2.151e-016 +3.333e-001
+1.111e-001 +1.111e-001 +2.222e-001
+2.222e-001 -1.111e-001 +1.111e-001
+4.444e-001 +1.111e-001 +5.556e-001
+2.546e-015
See Also
svd()
Parameters
[in]mAMatrix to pseudo invert.
[in]thresholdAlgorithm threshold.
Returns
Reference to changed calling matrix.

Definition at line 13073 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::gels ( bool  transpose,
const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  vErr 
) const throw (cvmexception)
inline

Overdetermined or underdetermined linear solver.

Creates object of type rmatrix as a solution of overdetermined or underdetermined linear systems

\[ A*x=b \]

for $m\times n$ matrix $A$ (or transposed one) where $b$ is a vector of length $k$ combined to

\[ A*X=B \]

for multiple vectors $b$ stored as columns of $k\times l$ matrix $B$ where $k=m$ in non-transposed case and $k=n$ otherwise. The algorithm uses QR or LQ factorization of $A$. It is assumed that $A$ has full rank, infinity returned otherwise. Internally function uses DGELS LAPACK routines. If $m>n$ and transpose=false or $m<n$ and transpose=true, then the system is overdetermined, thus the algorithm tries to find the least squares solution $x$ of the problem

\[ \|A*x-b\|_2\to\min\quad\text{or}\quad\|A^H*x-b\|_2\to\min\ \]

respectively. Real number dErr (or vector vErr for multiple vector $b$ case) returns residual sum of squares. The system is underdetermined otherwise, and the algorithm finds its minimum norm solution. In this case bErr is set to zero. In both cases the solution computed satisfies $\newcommand{\pinv}{\operatorname{pinv}} x=\pinv(A)*b$, but this algorithm is faster than pseudo inversion. Function throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(7, 5);
rmatrix b(7, 2);
rmatrix bt(5, 2);
rvector bv(5);
rvector vErr(2);
treal dErr;
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bt.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gels(false, b, vErr);
rvector vt = a.gels(true, bv, dErr);
rmatrix xt(7,2);
xt.gels(true, a, bt, vErr);
std::cout << (a.pinv()*b - x).norm() << std::endl;
std::cout << (~a.pinv()*bv - vt).norm() << std::endl;
std::cout << (~a.pinv()*bt - xt).norm() << std::endl;
prints
+2.6295387e-015
+5.8515615e-015
+6.6462869e-015
See Also
pinv()
Parameters
[in]transposeTrue to compute for transposed matrix $A$ (calling matrix).
[in]mBrmatrix $B$.
[out]vErrNorms of computation errors.
Returns
Result object.

Definition at line 13146 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::gels ( bool  transpose,
const basic_rmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  vErr 
) throw (cvmexception)
inline

Overdetermined or underdetermined linear solver.

Sets calling matrix to a solution of overdetermined or underdetermined linear systems

\[ A*x=b \]

for $m\times n$ matrix $A$ (or transposed one, parameter mA) where $b$ is a vector of length $k$ combined to

\[ A*X=B \]

for multiple vectors $b$ stored as columns of $k\times l$ matrix $B$ where $k=m$ in non-transposed case and $k=n$ otherwise. The algorithm uses QR or LQ factorization of $A$. It is assumed that $A$ has full rank, infinity returned otherwise. Internally function uses DGELS LAPACK routines. If $m>n$ and transpose=false or $m<n$ and transpose=true, then the system is overdetermined, thus the algorithm tries to find the least squares solution $x$ of the problem

\[ \|A*x-b\|_2\to\min\quad\text{or}\quad\|A^H*x-b\|_2\to\min\ \]

respectively. Real number dErr (or vector vErr for multiple vector $b$ case) returns residual sum of squares. The system is underdetermined otherwise, and the algorithm finds its minimum norm solution. In this case bErr is set to zero. In both cases the solution computed satisfies $\newcommand{\pinv}{\operatorname{pinv}} x=\pinv(A)*b$, but this algorithm is faster than pseudo inversion. Function throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(7, 5);
rmatrix b(7, 2);
rmatrix bt(5, 2);
rvector bv(5);
rvector vErr(2);
treal dErr;
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bt.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gels(false, b, vErr);
rvector vt = a.gels(true, bv, dErr);
rmatrix xt(7,2);
xt.gels(true, a, bt, vErr);
std::cout << (a.pinv()*b - x).norm() << std::endl;
std::cout << (~a.pinv()*bv - vt).norm() << std::endl;
std::cout << (~a.pinv()*bt - xt).norm() << std::endl;
prints
+2.6295387e-015
+5.8515615e-015
+6.6462869e-015
See Also
pinv()
Parameters
[in]transposeTrue to compute for transposed matrix $A$ (calling matrix).
[in]mArmatrix $A$.
[in]mBrmatrix $B$.
[out]vErrNorms of computation errors.
Returns
Reference to changed calling matrix.

Definition at line 13222 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector<TR> basic_rmatrix< TR >::gels ( bool  transpose,
const basic_rvector< TR > &  vB,
TR &  dErr 
) const throw (cvmexception)
inline

Overdetermined or underdetermined linear solver.

Creates object of type rvector as a solution of overdetermined or underdetermined linear system

\[ A*x=b \]

for $m\times n$ matrix $A$ (or transposed one) where $b$ is a vector of length $k$ where $k=m$ in non-transposed case and $k=n$ otherwise. The algorithm uses QR or LQ factorization of $A$. It is assumed that $A$ has full rank, infinity returned otherwise. Internally function uses DGELS LAPACK routines. If $m>n$ and transpose=false or $m<n$ and transpose=true, then the system is overdetermined, thus the algorithm tries to find the least squares solution $x$ of the problem

\[ \|A*x-b\|_2\to\min\quad\text{or}\quad\|A^H*x-b\|_2\to\min\ \]

respectively. Real number dErr returns residual sum of squares. The system is underdetermined otherwise, and the algorithm finds its minimum norm solution. In this case bErr is set to zero. In both cases the solution computed satisfies $\newcommand{\pinv}{\operatorname{pinv}} x=\pinv(A)*b$, but this algorithm is faster than pseudo inversion. Function throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(7, 5);
rmatrix b(7, 2);
rmatrix bt(5, 2);
rvector bv(5);
rvector vErr(2);
treal dErr;
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bt.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gels(false, b, vErr);
rvector vt = a.gels(true, bv, dErr);
rmatrix xt(7,2);
xt.gels(true, a, bt, vErr);
std::cout << (a.pinv()*b - x).norm() << std::endl;
std::cout << (~a.pinv()*bv - vt).norm() << std::endl;
std::cout << (~a.pinv()*bt - xt).norm() << std::endl;
prints
+2.6295387e-015
+5.8515615e-015
+6.6462869e-015
See Also
pinv()
Parameters
[in]transposeTrue to compute for transposed matrix $A$ (calling matrix).
[in]vBrvector $b$.
[out]dErrNorm of computation error.
Returns
Result object.

Definition at line 13295 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::gelsy ( const basic_rmatrix< TR > &  mB,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rmatrix object with the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using complete orthogonal factorization of $m\times n$ calling matrix $A$. Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsy(b, rank);
rvector xv = a.gelsy(bv, rank);
rmatrix x2(5,2);
x2.gelsy(a, b, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*x2 - b).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+3.3539762e-014
+5.2545344e-015
+3.3539762e-014
+4 +4
See Also
gelss()
gelsd()
rvector::gelsy()
rank()
Parameters
[in]mBrmatrix $B$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13360 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::gelsy ( const basic_rmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) throw (cvmexception)
inline

Linear least squares problem.

Function sets calling matrix to the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using complete orthogonal factorization of $m\times n$ matrix $A$ (parameter mA). Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsy(b, rank);
rvector xv = a.gelsy(bv, rank);
rmatrix x2(5,2);
x2.gelsy(a, b, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*x2 - b).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+3.3539762e-014
+5.2545344e-015
+3.3539762e-014
+4 +4
See Also
gelss()
gelsd()
rvector::gelsy()
rank()
Parameters
[in]mArmatrix $A$.
[in]mBrmatrix $B$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Reference to changed calling matrix.

Definition at line 13424 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector<TR> basic_rmatrix< TR >::gelsy ( const basic_rvector< TR > &  vB,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rvector object with the minimum-norm solution to linear least squares problem

\[ \|A*x-b\|_2\to\min \]

using complete orthogonal factorization of $m\times n$ calling matrix $A$. Here $b$ is a vector of length $m$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsy(b, rank);
rvector xv = a.gelsy(bv, rank);
rmatrix x2(5,2);
x2.gelsy(a, b, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*x2 - b).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+3.3539762e-014
+5.2545344e-015
+3.3539762e-014
+4 +4
See Also
gelss()
gelsd()
rvector::gelsy()
rank()
Parameters
[in]vBrvector $b$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13487 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::gelss ( const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rmatrix object with the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ calling matrix $A$. Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelss(b, sv, rank);
rvector xv = a.gelss(bv, sv, rank);
rmatrix xt(5,2);
xt.gelss(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.9169279e-014
+8.9260826e-015
+1.9169279e-014
+8.1402897e-015
+4 +4
See Also
gelsy()
gelsd()
rvector::gelss()
rank()
Parameters
[in]mBrmatrix $B$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13557 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::gelss ( const basic_rmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) throw (cvmexception)
inline

Linear least squares problem.

Function sets calling matrix to the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ matrix $A$ (parameter mA). Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelss(b, sv, rank);
rvector xv = a.gelss(bv, sv, rank);
rmatrix xt(5,2);
xt.gelss(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.9169279e-014
+8.9260826e-015
+1.9169279e-014
+8.1402897e-015
+4 +4
See Also
gelsy()
gelsd()
rvector::gelss()
rank()
Parameters
[in]mArmatrix $A$.
[in]mBrmatrix $B$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Reference to changed calling matrix.

Definition at line 13623 of file cvm.h.

template<typename TR>
basic_rvector<TR> basic_rmatrix< TR >::gelss ( const basic_rvector< TR > &  vB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rvector object with the minimum-norm solution to linear least squares problem

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ calling matrix $A$. Here $b$ is a vector of length $m$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelss(b, sv, rank);
rvector xv = a.gelss(bv, sv, rank);
rmatrix xt(5,2);
xt.gelss(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.9169279e-014
+8.9260826e-015
+1.9169279e-014
+8.1402897e-015
+4 +4
See Also
gelsy()
gelsd()
rvector::gelss()
rank()
Parameters
[in]vBrvector $b$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13688 of file cvm.h.

template<typename TR>
basic_rmatrix basic_rmatrix< TR >::gelsd ( const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rmatrix object with the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ calling matrix $A$ and divide and conquer method. Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsd(b, sv, rank);
rvector xv = a.gelsd(bv, sv, rank);
rmatrix xt(5,2);
xt.gelsd(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.0341178e-014
+6.0443462e-015
+1.0341178e-014
+8.9260826e-015
+4 +4
See Also
gelsy()
gelss()
rvector::gelss()
rank()
Parameters
[in]mBrmatrix $B$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13752 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::gelsd ( const basic_rmatrix< TR > &  mA,
const basic_rmatrix< TR > &  mB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) throw (cvmexception)
inline

Linear least squares problem.

Function sets calling matrix to the minimum-norm solutions to linear least squares problems

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ matrix $A$ (parameter mA) and divide and conquer method. Here $b$ is a vector of length $m$. Multiple vectors $b$ are stored as columns of $m\times l$ matrix $B$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsd(b, sv, rank);
rvector xv = a.gelsd(bv, sv, rank);
rmatrix xt(5,2);
xt.gelsd(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.0341178e-014
+6.0443462e-015
+1.0341178e-014
+8.9260826e-015
+4 +4
See Also
gelsy()
gelss()
rvector::gelss()
rank()
Parameters
[in]mArmatrix $A$.
[in]mBrmatrix $B$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Reference to changed calling matrix.

Definition at line 13818 of file cvm.h.

template<typename TR>
basic_rvector<TR> basic_rmatrix< TR >::gelsd ( const basic_rvector< TR > &  vB,
basic_rvector< TR > &  sv,
tint rank,
TR  tol = basic_cvmMachSp<TR>() 
) const throw (cvmexception)
inline

Linear least squares problem.

Function creates rvector object with the minimum-norm solution to linear least squares problem

\[ \|A*x-b\|_2\to\min \]

using singular value decomposition of $m\times n$ calling matrix $A$ and divide and conquer method. Here $b$ is a vector of length $m$. Matrix $A$ may be rank-deficient, function returns its effective rank in rank output parameter using tol tolerance. Internally function uses DGELSY LAPACK routines, see more details about the algorithm in those routines' documentation. Matrix $A$ is passed as argument mA. Function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rmatrix b(4, 2);
rvector bv(4);
rvector sv(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bv.randomize(-10., 10.);
rmatrix x = a.gelsd(b, sv, rank);
rvector xv = a.gelsd(bv, sv, rank);
rmatrix xt(5,2);
xt.gelsd(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (a*xv - bv).norm() << std::endl;
std::cout << (a*xt - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+1.0341178e-014
+6.0443462e-015
+1.0341178e-014
+8.9260826e-015
+4 +4
See Also
gelsy()
gelss()
rvector::gelss()
rank()
Parameters
[in]vBrvector $b$.
[out]svSingular values of $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Result object.

Definition at line 13884 of file cvm.h.

template<typename TR>
tint basic_rmatrix< TR >::rank ( TR  tol = basic_cvmMachSp<TR>()) const throw (cvmexception)
inline

Matrix rank.

Returns rank of calling matrix as number of singular values with normalized absolute value greater than or equal to parameter tol (this is the largest relative spacing by default). Function throws cvmexception in case of convergence error.

Example:
using namespace cvm;
try {
double a[] = {1., 2., 3., 4., 5., 6.,
7., 8., 9., 10., 11., 12.};
rmatrix m(a,3,4);
std::cout << m << m.rank() << std::endl;
m(3,4) = 13.;
std::cout << m.rank() << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1 4 7 10
2 5 8 11
3 6 9 12
2
3
See Also
rvector::svd()
rvector::normalize()
cvmMachSp()
Parameters
[in]tolRank computation tolerance.
Returns
tint Rank as integer.

Definition at line 13927 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
void basic_rmatrix< TR >::qr ( basic_rmatrix< TR > &  mQ,
basic_srmatrix< TR > &  mR 
) const throw (cvmexception)
inline

QR factorization ("economy" mode)

Computes QR factorization as

\[ M=QR \]

where $M$ is calling matrix, orthogonal matrix $Q$ and upper triangular (trapezoidal) matrix $R$ are mQ and mR output parameters respectively. This version implements so-called "economy" algorithm which for given $m\times n$ matrix $M$ computes $m\times n$ matrix $Q$ and $n\times n$ matrix $R$. See also full version. Function throws cvmexception in case if inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.qr(h,s3);
std::cout << (eye_real(2) - ~rmatrix(h,1,1,2,2)*rmatrix(h,1,1,2,2)).norm()
<< " " << (mh - h * s3).norm() << std::endl;
mh.qr(s2,h);
std::cout << (eye_real(2) - ~s2 * s2).norm()
<< " " << (mh - s2 * h).norm() << std::endl;
mv.qr(v,s2);
std::cout << (eye_real(2) - ~v * v).norm()
<< " " << (mv - v * s2).norm() << std::endl;
mv.qr(s3,v);
std::cout << (eye_real(3) - ~s3 * s3).norm()
<< " " << (mv - s3 * v).norm() << std::endl;
prints
+4.6933177e-16 +2.2342807e-15
+4.6933177e-16 +2.2342807e-15
+5.1302953e-16 +1.4432899e-15
+5.2889959e-16 +1.4432899e-15
Parameters
[out]mQrmatrix $Q$.
[out]mRsrmatrix $R$.

Definition at line 13989 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::qr ( basic_srmatrix< TR > &  mQ,
basic_rmatrix< TR > &  mR 
) const throw (cvmexception)
inline

QR factorization ("full" mode)

Computes QR factorization as

\[ M=QR \]

where $M$ is calling matrix, orthogonal matrix $Q$ and upper triangular (trapezoidal) matrix $R$ are mQ and mR output parameters respectively. This version implements so-called "full" algorithm which for given $m\times n$ matrix $M$ computes $m\times m$ matrix $Q$ and $m\times n$ matrix $R$. See also economy version. Function throws cvmexception in case if inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.qr(h,s3);
std::cout << (eye_real(2) - ~rmatrix(h,1,1,2,2)*rmatrix(h,1,1,2,2)).norm()
<< " " << (mh - h * s3).norm() << std::endl;
mh.qr(s2,h);
std::cout << (eye_real(2) - ~s2 * s2).norm()
<< " " << (mh - s2 * h).norm() << std::endl;
mv.qr(v,s2);
std::cout << (eye_real(2) - ~v * v).norm()
<< " " << (mv - v * s2).norm() << std::endl;
mv.qr(s3,v);
std::cout << (eye_real(3) - ~s3 * s3).norm()
<< " " << (mv - s3 * v).norm() << std::endl;
prints
+4.6933177e-16 +2.2342807e-15
+4.6933177e-16 +2.2342807e-15
+5.1302953e-16 +1.4432899e-15
+5.2889959e-16 +1.4432899e-15
Parameters
[out]mQsrmatrix $Q$.
[out]mRrmatrix $R$.

Definition at line 14041 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::lq ( basic_srmatrix< TR > &  mL,
basic_rmatrix< TR > &  mQ 
) const throw (cvmexception)
inline

LQ factorization ("economy" mode)

Computes LQ factorization as

\[ M=LQ \]

where $M$ is calling matrix, lower triangular (trapezoidal) matrix $L$ and orthogonal matrix $Q$ are mL and mQ output parameters respectively. This version implements so-called "economy" algorithm which for given $m\times n$ matrix $M$ computes $m\times m$ matrix $L$ and $m\times n$ matrix $Q$. See also full version. Function throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.lq(s2,h);
std::cout << (eye_real(2) - h * ~h).norm() << " " << (mh - s2 * h)
.norm() << std::endl;
mv.lq(s3,v);
std::cout << (eye_real(2) - ~rmatrix(v,1,1,2,2) * rmatrix(v,1,1,2,2))
.norm() << " " << (mv - s3 * v).norm() << std::endl;
mh.lq(h,s3);
std::cout << (eye_real(3) - s3 * ~s3).norm() << " " << (mh - h * s3)
.norm() << std::endl;
mv.lq(v,s2);
std::cout << (eye_real(2) - s2 * ~s2).norm() << " " << (mv - v * s2)
.norm() << std::endl;
prints
+8.6355085e-016 +3.3893638e-015
+1.9229627e-016 +1.6011864e-015
+1.0030483e-015 +3.3893638e-015
+1.9229627e-016 +1.6011864e-015
Parameters
[out]mLsrmatrix $L$.
[out]mQrmatrix $Q$.

Definition at line 14093 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::lq ( basic_rmatrix< TR > &  mL,
basic_srmatrix< TR > &  mQ 
) const throw (cvmexception)
inline

LQ factorization ("full" mode)

Computes LQ factorization as

\[ M=LQ \]

where $M$ is calling matrix, lower triangular (trapezoidal) matrix $L$ and orthogonal matrix $Q$ are mL and mQ output parameters respectively. This version implements so-called "full" algorithm which for given $m\times n$ matrix $M$ computes $m\times n$ matrix $L$ and $n\times n$ matrix $Q$. See also economy version. Function throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.lq(s2,h);
std::cout << (eye_real(2) - h * ~h).norm() << " " << (mh - s2 * h)
.norm() << std::endl;
mv.lq(s3,v);
std::cout << (eye_real(2) - ~rmatrix(v,1,1,2,2) * rmatrix(v,1,1,2,2))
.norm() << " " << (mv - s3 * v).norm() << std::endl;
mh.lq(h,s3);
std::cout << (eye_real(3) - s3 * ~s3).norm() << " " << (mh - h * s3)
.norm() << std::endl;
mv.lq(v,s2);
std::cout << (eye_real(2) - s2 * ~s2).norm() << " " << (mv - v * s2)
.norm() << std::endl;
prints
+8.6355085e-016 +3.3893638e-015
+1.9229627e-016 +1.6011864e-015
+1.0030483e-015 +3.3893638e-015
+1.9229627e-016 +1.6011864e-015
Parameters
[out]mLrmatrix $L$.
[out]mQsrmatrix $Q$.

Definition at line 14144 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::rq ( basic_srmatrix< TR > &  mR,
basic_rmatrix< TR > &  mQ 
) const throw (cvmexception)
inline

RQ factorization ("economy" mode)

Computes RQ factorization as

\[ M=RQ \]

where $M$ is calling matrix, upper triangular matrix $R$ and orthogonal matrix $Q$ are mR and mQ output parameters respectively. This version implements so-called "economy" algorithm which for given $m\times n$ matrix $M$ computes $m\times m$ matrix $R$ and $m\times n$ matrix $Q$. See also full version. Following this definition the implementation assumes that $m\le n$ is satisfied and throws cvmexception otherwise. Function also throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.rq(h,s3);
std::cout << (eye_real(2) - rmatrix(s3,2,1,2,3) * ~rmatrix(s3,2,1,2,3))
.norm() << " " << (mh - h * s3).norm() << std::endl;
mh.rq(s2,h);
std::cout << (eye_real(2) - h * ~h).norm()
<< " " << (mh - s2 * h).norm() << std::endl;
prints
+5.5511151e-016 +2.0471501e-015
+5.5511151e-016 +2.0471501e-015
Parameters
[out]mRsrmatrix $R$.
[out]mQrmatrix $Q$.

Definition at line 14191 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::rq ( basic_rmatrix< TR > &  mR,
basic_srmatrix< TR > &  mQ 
) const throw (cvmexception)
inline

RQ factorization ("full" mode)

Computes RQ factorization as

\[ M=RQ \]

where $M$ is calling matrix, upper triangular matrix $R$ and orthogonal matrix $Q$ are mR and mQ output parameters respectively. This version implements so-called "full" algorithm which for given $m\times n$ matrix $M$ computes $m\times n$ matrix $R$ and $n\times n$ matrix $Q$. See also economy version. Following this definition the implementation assumes that $m\le n$ is satisfied and throws cvmexception otherwise. Function also throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mh(a, 2, 3);
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix h(2,3), v(3,2);
mh.rq(h,s3);
std::cout << (eye_real(2) - rmatrix(s3,2,1,2,3) * ~rmatrix(s3,2,1,2,3))
.norm() << " " << (mh - h * s3).norm() << std::endl;
mh.rq(s2,h);
std::cout << (eye_real(2) - h * ~h).norm()
<< " " << (mh - s2 * h).norm() << std::endl;
prints
+5.5511151e-016 +2.0471501e-015
+5.5511151e-016 +2.0471501e-015
Parameters
[out]mRrmatrix $R$.
[out]mQsrmatrix $Q$.

Definition at line 14237 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::ql ( basic_rmatrix< TR > &  mQ,
basic_srmatrix< TR > &  mL 
) const throw (cvmexception)
inline

QL factorization ("economy" mode)

Computes QL factorization as

\[ M=QL \]

where $M$ is calling matrix, orthogonal matrix $Q$ and lower triangular matrix $L$ are mQ and mL output parameters respectively. This version implements so-called "economy" algorithm which for given $m\times n$ matrix $M$ computes $m\times n$ matrix $Q$ and $n\times n$ matrix $L$. See also full version. Following this definition the implementation assumes that $m\ge n$ is satisfied and throws cvmexception otherwise. Function also throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix v(3,2);
mv.ql(v,s2);
std::cout << (eye_real(2) - ~v * v).norm()
<< " " << (mv - v * s2).norm() << std::endl;
mv.ql(s3,v);
std::cout << (eye_real(2) - ~rmatrix(s3,1,2,3,2) * rmatrix(s3,1,2,3,2))
.norm() << " " << (mv - s3 * v).norm() << std::endl;
prints
+0.0000000e+000 +2.0947646e-015
+0.0000000e+000 +2.0947646e-015
Parameters
[out]mQrmatrix $Q$.
[out]mLsrmatrix $L$.

Definition at line 14283 of file cvm.h.

template<typename TR>
void basic_rmatrix< TR >::ql ( basic_srmatrix< TR > &  mQ,
basic_rmatrix< TR > &  mL 
) const throw (cvmexception)
inline

QL factorization ("full" mode)

Computes QL factorization as

\[ M=QL \]

where $M$ is calling matrix, orthogonal matrix $Q$ and lower triangular matrix $L$ are mQ and mL output parameters respectively. This version implements so-called "full" algorithm which for given $m\times n$ matrix $M$ computes $m\times m$ matrix $Q$ and $m\times n$ matrix $L$. See also economy version. Following this definition the implementation assumes that $m\ge n$ is satisfied and throws cvmexception otherwise. Function also throws cvmexception in case of inappropriate sizes of the operands passed.

Example:
using namespace cvm;
treal a[] = {1., 2., 3., 4., 5., 6.};
const cvm::rmatrix mv(a, 3, 2);
cvm::srmatrix s2(2), s3(3);
cvm::rmatrix v(3,2);
mv.ql(v,s2);
std::cout << (eye_real(2) - ~v * v).norm()
<< " " << (mv - v * s2).norm() << std::endl;
mv.ql(s3,v);
std::cout << (eye_real(2) - ~rmatrix(s3,1,2,3,2) * rmatrix(s3,1,2,3,2))
.norm() << " " << (mv - s3 * v).norm() << std::endl;
prints
+0.0000000e+000 +2.0947646e-015
+0.0000000e+000 +2.0947646e-015
Parameters
[out]mQsrmatrix $Q$.
[out]mLrmatrix $L$.

Definition at line 14328 of file cvm.h.

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::ger ( TR  alpha,
const RVector vCol,
const RVector vRow 
) throw (cvmexception)
inline

Rank-1 update matrix-vector operation.

Calls one of DGER routines of the BLAS library performing rank-1 update matrix-vector operation defined as

\[ M=\alpha\,\begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_m \end{pmatrix} \begin{pmatrix} y_1 & y_2 & \cdots & y_n \end{pmatrix} + M, \]

where $\alpha$ is real number (parameter alpha), $M$ is calling matrix and $x$ and $y$ are real vectors (parameters vCol and vRow respectively). Function returns reference to the matrix changed and throws cvmexception in case of inappropriate sizes of the operands. Function is not applicable to objects of the classes srbmatrix and srsmatrix (i.e. cvmexception would be thrown).

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (4);
try {
double alpha = 1.3;
rmatrix m(3,4);
rvector vc(3);
rvector vr(4);
m.randomize(-1., 2.); vc.randomize(-1., 3.); vr.randomize(0., 2.);
std::cout << m + vc.rank1update (vr) * alpha << std::endl;
std::cout << m.ger(alpha, vc, vr);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.7127e-01 2.9410e+00 1.3449e+00 3.6055e+00
1.9057e+00 2.6726e+00 1.7134e+00 2.2154e+00
1.7217e-01 1.3508e+00 8.8949e-01 2.2551e+00
-1.7127e-01 2.9410e+00 1.3449e+00 3.6055e+00
1.9057e+00 2.6726e+00 1.7134e+00 2.2154e+00
1.7217e-01 1.3508e+00 8.8949e-01 2.2551e+00
See Also
http://www.netlib.org/blas
rank1update()
basic_rvector<TR>::rank1update()
Parameters
[in]alphaMultiplier $\alpha$.
[in]vColrvector $x$.
[in]vRowrvector $y$.
Returns
Reference to changed calling matrix.

Definition at line 14392 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::gemm ( const basic_rmatrix< TR > &  m1,
bool  bTrans1,
const basic_rmatrix< TR > &  m2,
bool  bTrans2,
TR  dAlpha,
TR  dBeta 
) throw (cvmexception)
inline

Generic matrix-matrix operation.

Calls one of DGEMM routines of the BLAS library performing matrix-matrix operation defined as

\[ M=\alpha\,\mathcal{T}(M_1)\cdot\mathcal{T}(M_2) + \beta M, \]

where $\alpha$ and $\beta$ are real numbers (parameters dAlpha and dBeta), $M$ is calling matrix and $M_1$ and $M_2$ are matrices (parameters m1 and m2 respectively). Function $\mathcal{T}(M_i)$ transposes matrix $M_i$ if appropriate boolean parameter bTrans* is equal to true and does nothing otherwise. Function returns reference to the matrix changed and throws cvmexception in case of inappropriate sizes of the operands. Function is not applicable to objects of the classes srbmatrix and srsmatrix (i.e. exception of type cvmexception would be thrown).

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (4);
try {
double alpha = 1.3;
double beta = -0.7;
rmatrix m1(4,3); rmatrix m2(4,3);
rmatrix m(3,3);
m.randomize(-1., 2.); m1.randomize(-1., 3.); m2.randomize(0., 2.);
std::cout << ~m1 * m2 * alpha + m * beta << std::endl;
std::cout << m.gemm(m1, true, m2, false, alpha, beta);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
5.0504e+00 6.8736e+00 3.1171e+00
2.3915e+00 2.2544e+00 3.9205e+00
3.4607e+00 3.5351e+00 4.8622e+00
5.0504e+00 6.8736e+00 3.1171e+00
2.3915e+00 2.2544e+00 3.9205e+00
3.4607e+00 3.5351e+00 4.8622e+00
See Also
http://www.netlib.org/blas
Parameters
[in]m1rmatrix $M_1$.
[in]bTrans1Transpose rmatrix $M_1$.
[in]m2rmatrix $M_2$.
[in]bTrans2Transpose rmatrix $M_2$.
[in]dAlphaMultiplier $\alpha$.
[in]dBetaMultiplier $\beta$.
Returns
Reference to changed calling matrix.

Definition at line 14458 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::symm ( bool  bLeft,
const basic_srsmatrix< TR > &  ms,
const basic_rmatrix< TR > &  m,
TR  dAlpha,
TR  dBeta 
) throw (cvmexception)
inline

Generic symmetric matrix-matrix operation.

Calls one of DSYMM routines of the BLAS library performing one of matrix-matrix operations defined as

\[ M=\alpha\,M_s\cdot M_1 + \beta M\quad\text{or}\quad M=\alpha\,M_1\cdot M_s + \beta M, \]

where $\alpha$ and $\beta$ are real numbers (parameters dAlpha and dBeta), $M$ is calling matrix, $M_s$ is symmetric matrix and $M_1$ is real matrix (parameters ms and m respectively). First operation is performed if bLeft passed is true and second one otherwise. Function returns reference to the matrix changed and throws cvmexception in case of inappropriate sizes of the operands. Function is not applicable to objects of the class srbmatrix (i.e. cvmexception would be thrown).

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (4);
try {
double alpha = 1.3;
double beta = -0.7;
rmatrix m1(3,4);
rmatrix m2(4,3);
srsmatrix ms(3);
rmatrix m(3,4);
m.randomize(-1., 2.); m1.randomize(-1., 3.); m2.randomize(0., 2.);
ms.randomize(-3., 1.);
std::cout << ms * m1 * alpha + m * beta << std::endl;
std::cout << m.symm (true, ms, m1, alpha, beta) << std::endl;
m.resize(4,3);
std::cout << m2 * ms * alpha + m * beta << std::endl;
std::cout << m.symm (false, ms, m2, alpha, beta);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-3.3733e+00 -5.0566e+00 -6.3018e+00 -5.4907e+00
-1.8629e+00 -1.5133e+00 -1.1372e+00 -2.5557e+00
-3.5695e+00 -1.0012e+01 -1.4239e+00 -6.1786e-01
-3.3733e+00 -5.0566e+00 -6.3018e+00 -5.4907e+00
-1.8629e+00 -1.5133e+00 -1.1372e+00 -2.5557e+00
-3.5695e+00 -1.0012e+01 -1.4239e+00 -6.1786e-01
-6.4072e+00 7.0534e-01 1.5349e+00
-4.8219e+00 -6.9891e+00 -5.1766e+00
6.8503e-01 3.5828e+00 -3.2174e+00
2.3469e-01 -9.3921e-01 -2.1961e+00
-6.4072e+00 7.0534e-01 1.5349e+00
-4.8219e+00 -6.9891e+00 -5.1766e+00
6.8503e-01 3.5828e+00 -3.2174e+00
2.3469e-01 -9.3921e-01 -2.1961e+00
See Also
http://www.netlib.org/blas
Parameters
[in]bLeftPerfoem left-side operation.
[in]mssrsmatrix $M_s$.
[in]mrmatrix $M_1$.
[in]dAlphaMultiplier $\alpha$.
[in]dBetaMultiplier $\beta$.
Returns
Reference to changed calling matrix.

Definition at line 14541 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::vanish ( )
inline

Set matrix to zero.

Sets every element of calling matrix to be equal to zero and returns reference to the matrix changed. This function is faster than, for example, set(TR) with zero parameter passed.

Example:
using namespace cvm;
rmatrix m(3, 4);
m.randomize(0.,1.);
std::cout << m << std::endl;
std::cout << m.vanish ();
prints
0.856532 0.938261 0.275704 0.186834
0.651173 0.812159 0.100467 0.536912
0.0726646 0.695914 0.661824 0.554613
0 0 0 0
0 0 0 0
0 0 0 0
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 14580 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
basic_rmatrix& basic_rmatrix< TR >::randomize ( TR  dFrom,
TR  dTo 
)
inline

Randomizer.

Fills calling matrix with pseudo-random numbers distributed between dFrom and dTo. Function returns reference to the matrix changed.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (7);
rmatrix m(3,4);
m.randomize(-2.,3.);
std::cout << m;
prints
9.6853542e-01 2.7761467e+00 2.3791009e+00 -3.4452345e-01
2.9029511e+00 -9.5519883e-01 -4.9131748e-01 -1.2561113e+00
1.5219886e+00 -1.4494461e+00 2.8193304e+00 4.8817408e-01
Parameters
[in]dFromFirst limit.
[in]dToSecond limit.
Returns
Reference to changed calling matrix.

Reimplemented in basic_srsmatrix< TR >, basic_srbmatrix< TR >, and basic_srmatrix< TR >.

Definition at line 14611 of file cvm.h.

template<typename TR>
TR basic_rmatrix< TR >::norm2 ( ) const
inlineoverridevirtual

2-norm

2-norm of calling array that for vectors is defined as

\[ {\|x\|}_2={\|x\|}_E=\left(\sum_{i=1}^{n} |x_i|^2\right)^{1/2} \]

and for matrices as

\[ {\|A\|}_2=\max_i\sigma_i = \left(\max_{|x|=1}\, (Ax\cdot Ax)\right)^{1/2}, \]

where $\sigma_i$ is $i$-th singular value of $m\times n$ matrix $A,\ i=1,\dots,\min(m,n)$.

Example:
using namespace cvm;
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
double a[] = {1., 2., 3., -4., 5., -6.};
const rvector v (a, 3);
const rmatrix m (a, 2, 3);
std::cout << v << v.norm2 () << std::endl << std::endl;
std::cout << m << m.norm2 () << std::endl;
prints
+1.000000000000e+000 +2.000000000000e+000 +3.000000000000e+000
+3.741657386774e+000
+1.000000000000e+000 +3.000000000000e+000 +5.000000000000e+000
+2.000000000000e+000 -4.000000000000e+000 -6.000000000000e+000
+9.319612060784e+000
Returns
treal Norm value

Reimplemented from basic_array< TR, TR >.

Definition at line 14618 of file cvm.h.

Here is the call graph for this function:

Friends And Related Function Documentation

template<typename TR>
friend class basic_rvector< TR >
friend

Definition at line 10724 of file cvm.h.


The documentation for this class was generated from the following file: