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 | List of all members
basic_rvector< TR > Class Template Reference

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

#include <cvm.h>

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

Public Member Functions

 basic_rvector ()
 Default constructor.
 basic_rvector (tint nSize)
 Constructor.
 basic_rvector (std::initializer_list< TR > list)
 Constructor.
 basic_rvector (tint nSize, TR d)
 Constructor.
 basic_rvector (TR *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_rvector (const TR *pd, tint nSize, tint nIncr=1)
 Constructor.
 basic_rvector (const basic_rvector &v)
 Copy constructor.
 basic_rvector (basic_rvector &&a) noexcept
 Move constructor.
basic_rvectoroperator= (const basic_rvector &v) throw (cvmexception)
 Assignment operator.
basic_rvectoroperator= (basic_rvector &&a) throw (cvmexception)
 Move assignment operator.
basic_rvectorassign (const TR *pd, tint nIncr=1)
 External array assignment.
basic_rvectorassign (tint n, const TR *pd, tint nIncr=1)
 External array assignment (to tail)
basic_rvectorassign (tint n, const TR *pd, tint nSize, tint nIncr)
 External array assignment (range)
basic_rvectorassign (tint n, const basic_rvector &v) throw (cvmexception)
 Subvector assignment.
basic_rvectorset (TR d)
 Sets all elements to one value.
basic_rvectorresize (tint nNewSize) throw (cvmexception)
 Changes size of vector.
bool operator== (const basic_rvector &v) const
 Vector comparison.
bool operator!= (const basic_rvector &v) const
 Vector comparison.
basic_rvectoroperator<< (const basic_rvector &v) throw (cvmexception)
 Vector replacement.
basic_rvector operator+ (const basic_rvector &v) const throw (cvmexception)
 Addition operator.
basic_rvector operator- (const basic_rvector &v) const throw (cvmexception)
 Subtraction operator.
basic_rvectorsum (const basic_rvector &v1, const basic_rvector &v2) throw (cvmexception)
 Sum of vectors.
basic_rvectordiff (const basic_rvector &v1, const basic_rvector &v2) throw (cvmexception)
 Difference of vectors.
basic_rvectoroperator+= (const basic_rvector &v) throw (cvmexception)
 Increment operator.
basic_rvectoroperator-= (const basic_rvector &v) throw (cvmexception)
 Decrement operator.
basic_rvector operator- () const throw (cvmexception)
 Unary minus operator.
basic_rvector operator* (TR dMult) const throw (cvmexception)
 Multiply by number operator.
basic_rvector operator/ (TR dDiv) const throw (cvmexception)
 Divide by number operator.
basic_rvectoroperator*= (TR dMult)
 Multiply by number and assign.
basic_rvectoroperator/= (TR dDiv) throw (cvmexception)
 Divide by number and assign.
basic_rvectornormalize ()
 Vector normalizer.
TR operator* (const basic_rvector &v) const throw (cvmexception)
 Scalar product.
basic_rvector operator* (const basic_rmatrix< TR > &m) const throw (cvmexception)
 Vector-matrix product.
basic_rvectormult (const basic_rvector &v, const basic_rmatrix< TR > &m) throw (cvmexception)
 Vector-matrix product.
basic_rvectormult (const basic_rmatrix< TR > &m, const basic_rvector &v) throw (cvmexception)
 Matrix-vector product.
basic_rmatrix< TR > rank1update (const basic_rvector &v) const
 Rank-1 update.
basic_rvectorsolve (const basic_srmatrix< TR > &mA, const basic_rvector &vB, TR &dErr) throw (cvmexception)
 Linear solver.
basic_rvectorsolve_tran (const basic_srmatrix< TR > &mA, const basic_rvector &vB, TR &dErr) throw (cvmexception)
 Linear solver (transposed)
basic_rvectorsolve (const basic_srmatrix< TR > &mA, const basic_rvector &vB) throw (cvmexception)
 Linear solver.
basic_rvectorsolve_tran (const basic_srmatrix< TR > &mA, const basic_rvector &vB) throw (cvmexception)
 Linear solver (transposed)
basic_rvector operator/ (const basic_srmatrix< TR > &mA) const throw (cvmexception)
 Linear solver operator (transposed)
basic_rvector operator% (const basic_srmatrix< TR > &mA) const throw (cvmexception)
 Linear solver operator.
basic_rvectorsolve_lu (const basic_srmatrix< TR > &mA, const basic_srmatrix< TR > &mLU, const tint *pPivots, const basic_rvector &vB, TR &dErr) throw (cvmexception)
 LU factorization based linear solver.
basic_rvectorsolve_lu (const basic_srmatrix< TR > &mA, const basic_srmatrix< TR > &mLU, const tint *pPivots, const basic_rvector &vB) throw (cvmexception)
 LU factorization based linear solver.
basic_rvectorgels (bool transpose, const basic_rmatrix< TR > &mA, const basic_rvector &vB, TR &dErr) throw (cvmexception)
 Overdetermined or underdetermined linear solver.
basic_rvectorgelsy (const basic_rmatrix< TR > &mA, const basic_rvector &vB, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvectorgelss (const basic_rmatrix< TR > &mA, const basic_rvector &vB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvectorgelsd (const basic_rmatrix< TR > &mA, const basic_rvector &vB, basic_rvector< TR > &sv, tint &rank, TR tol=basic_cvmMachSp< TR >()) throw (cvmexception)
 Linear least squares problem.
basic_rvectorsvd (const basic_rmatrix< TR > &mA) throw (cvmexception)
 Singular value decomposition.
basic_rvectorsvd (const basic_cmatrix< TR, TC > &mA) throw (cvmexception)
 Singular value decomposition.
basic_rvectorsvd (const basic_rmatrix< TR > &mA, basic_srmatrix< TR > &mU, basic_srmatrix< TR > &mVH) throw (cvmexception)
 Singular value decomposition.
basic_rvectorsvd (const basic_cmatrix< TR, TC > &mA, basic_scmatrix< TR, TC > &mU, basic_scmatrix< TR, TC > &mVH) throw (cvmexception)
 Singular value decomposition.
basic_rvectoreig (const basic_srsmatrix< TR > &mA) throw (cvmexception)
 Eigenvalues.
basic_rvectoreig (const basic_srsmatrix< TR > &mA, basic_srmatrix< TR > &mEigVect) throw (cvmexception)
 Eigenvalues.
basic_rvectoreig (const basic_schmatrix< TR, TC > &mA) throw (cvmexception)
 Eigenvalues.
basic_rvectoreig (const basic_schmatrix< TR, TC > &mA, basic_scmatrix< TR, TC > &mEigVect) throw (cvmexception)
 Eigenvalues.
basic_rvectorgemv (bool bLeft, const basic_rmatrix< TR > &m, TR dAlpha, const basic_rvector &v, TR dBeta) throw (cvmexception)
 Generic matrix-vector operation.
basic_rvectorgbmv (bool bLeft, const basic_srbmatrix< TR > &m, TR dAlpha, const basic_rvector &v, TR dBeta) throw (cvmexception)
 Generic band matrix-vector operation.
basic_rvectorrandomize (TR dFrom, TR dTo)
 Randomizer.
- 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
TR & operator() (tint n) throw (cvmexception)
 Reference to element (l-value)
TR operator() (tint n) const throw (cvmexception)
 Value of element (not l-value)
TR & operator[] (tint n) throw (cvmexception)
 Reference to element (l-value)
TR operator[] (tint n) const throw (cvmexception)
 Value of element (not l-value)
basic_arrayassign (const TR *p)
 Assignment from external array.
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
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.
virtual TR norminf () const
 Infinity norm.
virtual TR norm1 () const
 1-norm
virtual TR norm2 () const
 2-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

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 Attributes inherited from basic_array< TR, TR >
tint msz
 Number of elements of type TC allocated.
tint mincr
 Increment (distance) between elements (default is 1, i.e. elements follow each other)
std::shared_ptr< TR > mp
 native data pointer
TR * mpf
 Foreign data pointer.

Detailed Description

template<typename TR>
class basic_rvector< TR >

End-user class encapsulating vector of real numbers.

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

See Also
basic_array

Definition at line 3307 of file cvm.h.

Constructor & Destructor Documentation

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

Default constructor.

Creates zero size rvector. No memory gets allocated.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
std::cout << v.size() << std::endl;
v.resize (5);
v(1) = 1.5;
std::cout << v;
prints
0
1.50e+000 0.00e+000 0.00e+000 0.00e+000 0.00e+0000
See Also
resize()

Definition at line 3337 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( tint  nSize)
inlineexplicit

Constructor.

Creates rvector object of given size. It throws cvmexception in case of non-positive size passed or memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v (5);
std::cout << v;
prints
0.00e+000 0.00e+000 0.00e+000 0.00e+000 0.00e+000
Parameters
[in]nSizeSize of rvector (must be positive).

Definition at line 3361 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( std::initializer_list< TR >  list)
inline

Constructor.

Creates rvector object and fills it with values provided in the initializer list. This constructor is available only if your compiler supports initializer lists (GCC 4.4 and higher, MS Visual Studio 2013 and higher, Apple LLVM 5.0 and higher).

Example:
using namespace cvm;
std::cout.setf(std::ios::scientific | std::ios::left);
std::cout.precision(3);
rvector v = { 1, -2, 3.456, 99.99 };
std::cout << v;
prints
1.000e+000 - 2.000e+000 3.456e+000 9.999e+001
Parameters
[in]listInitializer list as shown above.

Definition at line 3388 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( tint  nSize,
TR  d 
)
inline

Constructor.

Creates rvector object of given size and fills it with given number. It throws cvmexception in case of non-positive size passed or memory allocation failure.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v (5, 1.5);
std::cout << v;
prints
1.50e+00 1.50e+00 1.50e+00 1.50e+00 1.50e+00
Parameters
[in]nSizeSize of rvector (must be positive).
[in]dNumber to fill rvector in.

Definition at line 3420 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( TR *  pd,
tint  nSize,
tint  nIncr = 1 
)
inline

Constructor.

Creates rvector object of given size with given increment between elements (default is 1). It throws cvmexception in case of non-positive size passed. Unlike others, this constructor does not allocate memory. It just shares memory with array pointed to by pd using distance between elements equal to nIncr. It is intented to make possible the following syntax:

rmatrix m (10, 20);
rvector v (20);
m[1] = v; // assigns v to the 1st row of m

And for example this code...

rmatrix m (10,20);
rvector vRow = m[1];

will also call this constructor and memory will be shared.

If you need the code like this with memory allocation, use the following:

rmatrix m (10,20);
rvector vRow (m.msize());
vRow = m[1];
Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
double a[] = {7., 7., 7., 7., 7., 7., 7.,};
rvector v1 (a, 4, 2);
std::cout << v1;
v1(2) = 1.23;
std::cout << v1 << std::endl;
for (int i = 0; i < 3; i++) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
rvector v2 (a, 5);
std::cout << v2;
prints
7.00e+000 7.00e+000 7.00e+000 7.00e+000
7.00e+000 1.23e+000 7.00e+000 7.00e+000
7.00e+000 7.00e+000 1.23e+000
7.00e+000 7.00e+000 1.23e+000 7.00e+000 7.00e+000
See Also
http://cvmlib.com/faq.htm
Parameters
[in]pdPointer to array to share memory with.
[in]nSizeSize of rvector (must be positive).
[in]nIncrIncrement between elements, default is 1 (one after another).

Definition at line 3490 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( const TR *  pd,
tint  nSize,
tint  nIncr = 1 
)
inline

Constructor.

Creates rvector of nSize elements with increment 1 in between. This is const version, it allocates memory and copies every nIncr-th element (deep copy) from external array pointed to by pd parameter. It copies nSize elements total.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
const double a[] = {7., 7., 7., 7., 7., 7., 7.,};
rvector v1 (a, 4, 2);
std::cout << v1;
v1(2) = 1.23;
std::cout << v1 << std::endl;
for (int i = 0; i < 3; i++) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
rvector v2 (a, 5);
std::cout << v2;
prints
7.00e+000 7.00e+000 7.00e+000 7.00e+000
7.00e+000 1.23e+000 7.00e+000 7.00e+000
7.00e+000 7.00e+000 7.00e+000
7.00e+000 7.00e+000 7.00e+000 7.00e+000 7.00e+000
See Also
http://cvmlib.com/faq.htm
Parameters
[in]pdConst pointer to external array.
[in]nSizeNumber of array elements.
[in]nIncrIncrement between external array elements.

Definition at line 3536 of file cvm.h.

template<typename TR>
basic_rvector< TR >::basic_rvector ( const basic_rvector< TR > &  v)
inline

Copy constructor.

Creates rvector object of size equal to size of vector v and sets every element of created vector to be equal to appropriate element of v. 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);
double a[] = {1., 2., 3., 4., 5., 6., 7.,};
const rvector v (a, 4, 2);
rvector vc (v);
vc(1) = 77.;
std::cout << vc;
std::cout << v;
prints
7.70e+001 3.00e+000 5.00e+000 7.00e+000
1.00e+000 3.00e+000 5.00e+000 7.00e+000
Parameters
[in]vVector to copy from.

Definition at line 3570 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector< TR >::basic_rvector ( basic_rvector< TR > &&  a)
inline

Move constructor.

Implements move semantics introduced in new C++ standard. Moves data ownership from other array 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]arvalue reference to other array.

Definition at line 3579 of file cvm.h.

Member Function Documentation

template<typename TR>
basic_rvector& basic_rvector< TR >::operator= ( const basic_rvector< TR > &  v) throw (cvmexception)
inline

Assignment operator.

Sets every element of calling rvector to be equal to appropriate element of vector v and returns reference to the vector changed. Operator throws cvmexception in case of different vector sizes.

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.};
const rvector v (a, 5);
rvector vc(5);
vc = v;
std::cout << vc;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+000 2.00e+000 3.00e+000 4.00e+000 5.00e+000
Parameters
[in]vrvector to assign from.
Returns
Reference to changed calling vector.

Definition at line 3616 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::operator= ( basic_rvector< TR > &&  a) throw (cvmexception)
inline

Move assignment operator.

Implements move semantics introduced in new C++ standard. Moves data ownership from other array 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]arvalue reference to other array.

Definition at line 3626 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::assign ( const TR *  pd,
tint  nIncr = 1 
)
inline

External array assignment.

Sets every element of calling vector to be equal to every nIncr-th element of array pointed to by parameter pd and returns reference to the vector changed. It's assumed that array passed is long enough to fill calling vector.

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., 7.,};
rvector v (5);
rvector v2 (4);
v.assign(a);
v2.assign(a, 2);
std::cout << v;
std::cout << v2;
prints
1.00e+000 2.00e+000 3.00e+000 4.00e+000 5.00e+000
1.00e+000 3.00e+000 5.00e+000 7.00e+000
Parameters
[in]pdConst pointer to external array.
[in]nIncrIncrement between elements in external array.
Returns
Reference to changed calling vector.

Definition at line 3664 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::assign ( tint  n,
const TR *  pd,
tint  nIncr = 1 
)
inline

External array assignment (to tail)

Sets every element of calling vector, starting from CVM0 based n-th one till the end, to be equal to every nIncr-th element of array pointed to by parameter pd and returns reference to the vector changed.

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.};
rvector v (5);
rvector v2 (5);
v.assign(2, a);
v2.assign(3, a, 2);
std::cout << v;
std::cout << v2;
prints
0.00e+000 1.00e+000 2.00e+000 3.00e+000 4.00e+000
0.00e+000 0.00e+000 1.00e+000 3.00e+000 5.00e+000
Parameters
[in]nStart rvector index to assign from.
[in]pdConst pointer to external array.
[in]nIncrIncrement between elements in external array.
Returns
Reference to changed calling vector.

Definition at line 3701 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::assign ( tint  n,
const TR *  pd,
tint  nSize,
tint  nIncr 
)
inline

External array assignment (range)

Sets every element of calling vector, starting from CVM0 based n-th one, up to nSize total, to be equal to every nIncr-th element of array pointed to by parameter pd and returns reference to the vector changed. If n+nSize goes beyond rvector boundaries assignment stops at the last element.

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., 7.};
rvector v (5);
v.assign(2, a, 5, 2);
std::cout << v;
v.assign(2, a, 3, 1);
std::cout << v;
prints
0.00e+000 1.00e+000 3.00e+000 5.00e+000 7.00e+000
0.00e+000 1.00e+000 2.00e+000 3.00e+000 7.00e+000
Parameters
[in]nStart rvector index to assign from.
[in]pdConst pointer to external array.
[in]nSizeMaximum number of elements to be assigned.
[in]nIncrIncrement between elements in external array.
Returns
Reference to changed calling vector.

Definition at line 3742 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::assign ( tint  n,
const basic_rvector< TR > &  v 
) throw (cvmexception)
inline

Subvector assignment.

Sets every element of calling vector's sub-vector beginning with CVM0 based index n to vector v and returns reference to the vector changed. Function throws cvmexception if n is not positive or v.size()+n-1 is greater than calling vector's size.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v1(5);
rvector v2(2);
v1.set(1.);
v2.set(2.);
v1.assign(3, v2);
std::cout << v1;
prints
1.00e+00 1.00e+00 2.00e+00 2.00e+00 1.00e+00
Parameters
[in]nStart rvector index to assign from.
[in]vConst reference to vector.
Returns
Reference to changed calling vector.

Definition at line 3780 of file cvm.h.

Here is the call graph for this function:

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

Sets all elements to one value.

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

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v(5);
v.set(3.);
std::cout << v;
prints
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 vector.

Reimplemented from basic_array< TR, TR >.

Definition at line 3809 of file cvm.h.

template<typename TR>
basic_rvector& basic_rvector< TR >::resize ( tint  nNewSize) throw (cvmexception)
inline

Changes size of vector.

Changes size of calling vector to be equal to nNewSize and returns reference to the vector changed. In case of increasing of its size, the vector is filled up with zeroes. Function throws cvmexception in case of negative size 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.};
rvector v (a, 3);
std::cout << v;
v.resize(2);
std::cout << v;
v.resize(4);
std::cout << v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+00 2.00e+00 3.00e+00
1.00e+00 2.00e+00
1.00e+00 2.00e+00 0.00e+00 0.00e+00
Parameters
[in]nNewSizeNew size.
Returns
Reference to changed calling vector.

Reimplemented from basic_array< TR, TR >.

Definition at line 3852 of file cvm.h.

template<typename TR>
bool basic_rvector< TR >::operator== ( const basic_rvector< TR > &  v) const
inline

Vector comparison.

Operator compares calling vector with vector v 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.};
rvector v1 (a, 4);
rvector v2 (4);
v2 (1) = 1.; v2 (2) = 2.;
v2 (3) = 3.; v2 (4) = 4.;
cout << (v1 == v2) << endl;
prints
1
See Also
operator !=()
Parameters
[in]vrvector to compare to.
Returns
bool Result of comparison.

Definition at line 3887 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
bool basic_rvector< TR >::operator!= ( const basic_rvector< TR > &  v) const
inline

Vector comparison.

Operator compares calling vector with vector v 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.};
rvector v1 (a, 4);
rvector v2 (4);
v2 (1) = 1.; v2 (2) = 2.;
v2 (3) = 3.; v2 (4) = 4.;
cout << (v1 != v2) << endl;
prints
0
See Also
operator ==()
Parameters
[in]vrvector to compare to.
Returns
bool Result of comparison.

Definition at line 3920 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::operator<< ( const basic_rvector< TR > &  v) throw (cvmexception)
inline

Vector replacement.

Destroys calling vector, creates a new one as a copy of v and returns reference to the vector 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 {
rvector v (5);
rvector vc (3);
v(1) = 1.;
v(2) = 2.;
std::cout << v << vc << std::endl;
vc << v;
std::cout << vc;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.00e+000 2.00e+000 0.00e+000 0.00e+000 0.00e+000
0.00e+000 0.00e+000 0.00e+000
1.00e+000 2.00e+000 0.00e+000 0.00e+000 0.00e+000
See Also
operator =()
Parameters
[in]vrvector to replace by.
Returns
Reference to changed calling vector.

Definition at line 3961 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector basic_rvector< TR >::operator+ ( const basic_rvector< TR > &  v) const throw (cvmexception)
inline

Addition operator.

Creates object of type rvector as sum of calling vector and vector v. Operator throws cvmexception in case of different sizes of the operands 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.};
const double b[] = {3., 5., 7., 9.};
const rvector va (a, 4);
rvector vb (4);
vb.assign(b);
std::cout << va + vb;
std::cout << va + va;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
4.00e+000 7.00e+000 1.00e+001 1.30e+001
2.00e+000 4.00e+000 6.00e+000 8.00e+000
See Also
sum()
Parameters
[in]vrvector to add to calling one.
Returns
Sum of vectors.

Definition at line 4005 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector basic_rvector< TR >::operator- ( const basic_rvector< TR > &  v) const throw (cvmexception)
inline

Subtraction operator.

Creates object of type rvector as difference of calling vector and vector v. It throws cvmexception in case of different sizes of the operands 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.};
const double b[] = {3., 5., 7., 9.};
const rvector va (a, 4);
rvector vb (4);
vb.assign(b);
std::cout << va - vb;
std::cout << va - va;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-2.00e+000 -3.00e+000 -4.00e+000 -5.00e+000
0.00e+000 0.00e+000 0.00e+000 0.00e+000
See Also
diff()
Parameters
[in]vrvector to subtract from calling one.
Returns
Difference of vectors.

Definition at line 4049 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::sum ( const basic_rvector< TR > &  v1,
const basic_rvector< TR > &  v2 
) throw (cvmexception)
inline

Sum of vectors.

Assigns sum of vectors v1 and v2 to calling vector and returns reference to the vector changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4.};
double b[] = {2., 3., 4., 5.};
rvector va (a, 4);
rvector vb (b, 4);
rvector v (4);
std::cout << v.sum(va, vb);
std::cout << v.sum(v, va);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.00e+00 5.00e+00 7.00e+00 9.00e+00
4.00e+00 7.00e+00 1.00e+01 1.30e+01
See Also
operator +()
Parameters
[in]v1First rvector summand.
[in]v2Second rvector summand.
Returns
Reference to changed calling vector.

Definition at line 4094 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::diff ( const basic_rvector< TR > &  v1,
const basic_rvector< TR > &  v2 
) throw (cvmexception)
inline

Difference of vectors.

Assigns difference of vectors v1 and v2 to calling vector and returns reference to the vector changed. It throws cvmexception in case of different sizes of the operands.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4.};
double b[] = {2., 3., 4., 5.};
rvector va (a, 4);
rvector vb (b, 4);
rvector v (4);
std::cout << v.diff(va, vb);
std::cout << v.diff(v, va);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.00e+00 -1.00e+00 -1.00e+00 -1.00e+00
-2.00e+00 -3.00e+00 -4.00e+00 -5.00e+00
See Also
operator -()
Parameters
[in]v1First rvector subtrahend.
[in]v2Second rvector subtrahend.
Returns
Reference to changed calling vector.

Definition at line 4139 of file cvm.h.

Here is the call graph for this function:

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

Increment operator.

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

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rvector v1 (4);
rvector v2 (4);
v1.set(1.);
v2.set(2.);
v1 += v2;
std::cout << v1;
// well, you can do this too, but temporary object would be created
v2 += v2;
std::cout << v2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.00e+00 3.00e+00 3.00e+00 3.00e+00
4.00e+00 4.00e+00 4.00e+00 4.00e+00
See Also
operator +()
sum()
Parameters
[in]vrvector to increment by.
Returns
Reference to changed calling vector.

Definition at line 4186 of file cvm.h.

Here is the call graph for this function:

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

Decrement operator.

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

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rvector v1 (4);
rvector v2 (4);
v1.set(1.);
v2.set(2.);
v1 -= v2;
std::cout << v1;
// well, you can do this too, but temporary object would be created
v2 -= v2;
std::cout << v2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-1.00e+00 -1.00e+00 -1.00e+00 -1.00e+00
0.00e+00 0.00e+00 0.00e+00 0.00e+00
See Also
operator -()
diff()
Parameters
[in]vrvector to decrement by.
Returns
Reference to changed calling vector.

Definition at line 4232 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector basic_rvector< TR >::operator- ( ) const throw (cvmexception)
inline

Unary minus operator.

Creates object of type rvector as calling vector multiplied by -1. 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.};
const rvector v (a, 4);
std::cout << - v;
prints
-1.00e+00 -2.00e+00 -3.00e+00 -4.00e+00
Returns
Result object.

Definition at line 4262 of file cvm.h.

template<typename TR>
basic_rvector basic_rvector< TR >::operator* ( TR  dMult) const throw (cvmexception)
inline

Multiply by number operator.

Creates object of type rvector as product of calling vector and number dMult. 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.};
const rvector v (a, 4);
std::cout << v * 5.;
prints
5.00e+00 1.00e+01 1.50e+01 2.00e+01
See Also
operator *=()
Parameters
[in]dMultNumber to multiply by.
Returns
Result object.

Definition at line 4295 of file cvm.h.

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

Divide by number operator.

Creates object of type rvector as quotient of calling vector 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.};
const rvector v (a, 4);
std::cout << v / 2.;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
5.00e-01 1.00e+00 1.50e+00 2.00e+00
See Also
operator /=()
Parameters
[in]dDivNumber to divide by.
Returns
Result object.

Definition at line 4334 of file cvm.h.

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

Multiply by number and assign.

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

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v (4);
v.set(2.);
v *= 2.
std::cout << v;
prints
4.00e+00 4.00e+00 4.00e+00 4.00e+00
See Also
operator *(TR) const
Parameters
[in]dMultNumber to multiply by.
Returns
Reference to changed calling vector.

Definition at line 4365 of file cvm.h.

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

Divide by number and assign.

Divides calling vector by number dDiv and returns reference to the vector 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 {
rvector v (4);
v.set(3.);
v /= 2.;
std::cout << v;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
1.50e+00 1.50e+00 1.50e+00 1.50e+00
See Also
operator /(TR) const
Parameters
[in]dDivNumber to divide by.
Returns
Reference to changed calling vector.

Definition at line 4402 of file cvm.h.

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

Vector normalizer.

Normalizes calling vector 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);
rvector v(4);
v(1) = 1.;
v(2) = 2.;
v(3) = 3.;
v(4) = 4.;
std::cout << v.normalize();
std::cout << v.norm() << std::endl;
prints
1.83e-01 3.65e-01 5.48e-01 7.30e-01
1.00e+00
Returns
Reference to changed calling vector.

Definition at line 4436 of file cvm.h.

Here is the caller graph for this function:

template<typename TR>
TR basic_rvector< TR >::operator* ( const basic_rvector< TR > &  v) const throw (cvmexception)
inline

Scalar product.

Scalar product of calling vector and vector v. It throws cvmexception if the operands have different sizes.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
double a[] = {1., 2., 3., 4.};
rvector v1(4);
rvector v2(4);
v1.assign(a);
v2.assign(a);
std::cout << v1 * v2 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
3.00e+01
Parameters
[in]vrvector to compute scalar product with.
Returns
TR Scalar product as treal.

Definition at line 4473 of file cvm.h.

Here is the call graph for this function:

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

Vector-matrix product.

Creates object of type rvector as product of calling vector and matrix m. Use mult() function to avoid new object creation. Operator throws cvmexception if calling vector's size differs from number of rows in matrix m.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rvector v(2);
rmatrix m(2, 3);
v.set(2.);
m.set(1.);
std::cout << v * m;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
4.00e+00 4.00e+00 4.00e+00
Parameters
[in]mrmatrix to multiply calling vector by.
Returns
Result object.

Definition at line 4512 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::mult ( const basic_rvector< TR > &  v,
const basic_rmatrix< TR > &  m 
) throw (cvmexception)
inline

Vector-matrix product.

Sets calling vector to be equal to product of vector v by matrix m and returns reference to the object changed.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rvector v2(2), v3(3);
rmatrix m(2, 3);
v2.set(2.);
m.set(1.);
std::cout << v3.mult(v2, m);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
4.00e+00 4.00e+00 4.00e+00
Parameters
[in]vrvector to multiply by matrix m.
[in]mrmatrix to multiply vector v by.
Returns
Reference to changed calling vector.

Definition at line 4551 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::mult ( const basic_rmatrix< TR > &  m,
const basic_rvector< TR > &  v 
) throw (cvmexception)
inline

Matrix-vector product.

Sets calling vector to be equal to product of matrix m by vector v by and returns reference to the object changed.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
try {
rvector v2(2), v3(3);
rmatrix m(2, 3);
v3.set(2.);
m.set(1.);
std::cout << v2.mult(m, v3);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
6.00e+00 6.00e+00
Parameters
[in]mrmatrix to multiply by vector v.
[in]vrvector to multiply matrix m by.
Returns
Reference to changed calling vector.

Definition at line 4590 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rmatrix<TR> basic_rvector< TR >::rank1update ( const basic_rvector< TR > &  v) const
inline

Rank-1 update.

Creates object of type rmatrix as rank-1 update of calling vector and vector v. 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;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (2);
rvector v1(3);
rvector v2(2);
v1.set(2.);
v2.set(2.);
std::cout << v1.rank1update (v2);
prints
4.00e+00 4.00e+00
4.00e+00 4.00e+00
4.00e+00 4.00e+00
Parameters
[in]vrvector to compute rank-1 update with.
Returns
Result object.

Definition at line 4641 of file cvm.h.

Here is the call graph for this function:

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

Linear solver.

Sets calling vector to be equal to solution $x$ of linear equation $A*x=b$ where parameter mA is square matrix $A$ and parameter vB is vector $b$. Function returns reference to the vector 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 objects or when matrix $A$ is close to singular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
double dErr = 0.;
std::cout << vx.solve (ma, vb, dErr);
std::cout << dErr << std::endl;
std::cout << ma * vx - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+8.000000000000e+00 -8.000000000000e+00 +3.000000000000e+00
+6.661338147751e-15
+0.000000000000e+00 +0.000000000000e+00 +0.000000000000e+00
See Also
solve(const basic_srmatrix<TR>&,const basic_rvector<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]vBrvector $b$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling vector.

Definition at line 4695 of file cvm.h.

Here is the caller graph for this function:

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

Linear solver (transposed)

Sets calling vector to be equal to solution $x$ of linear equation $A^T*x=b$ (which is equivalent to $x*A=b$) where parameter mA is square matrix $A$ and parameter vB is vector $b$. Function returns reference to the vector 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 objects or when matrix $A$ is close to ingular.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
double dErr = 0.;
std::cout << vx.solve_tran (ma, vb, dErr);
std::cout << dErr << std::endl;
std::cout << vx * ma - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+1.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
+7.105427357601e-015
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
solve_tran(const basic_srmatrix<TR>&,const basic_rvector<TR>&)
Parameters
[in]mAsrmatrix $A$.
[in]vBrvector $b$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling vector.

Definition at line 4746 of file cvm.h.

Here is the caller graph for this function:

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

Linear solver.

Sets calling vector to be equal to solution $x$ of linear equation $A*x=b$ where parameter mA is square matrix $A$ and parameter vB is vector $b$. Function returns reference to the vector changed. Function 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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
std::cout << vx.solve (ma, vb);
std::cout << ma * vx - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+8.000000000000e+00 -8.000000000000e+00 +3.000000000000e+00
+0.000000000000e+00 +0.000000000000e+00 +0.000000000000e+00
See Also
solve(const basic_srmatrix<TR>&,const basic_rvector<TR>&,TR&)
operator%(const basic_srmatrix<TR>&)const
Parameters
[in]mAsrmatrix $A$.
[in]vBrvector $b$.
Returns
Reference to changed calling vector.

Definition at line 4791 of file cvm.h.

Here is the call graph for this function:

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

Linear solver (transposed)

Sets calling vector to be equal to solution $x$ of linear equation $A^T*x=b$ (which is equivalent to $x*A=b$) where parameter mA is square matrix $A$ and parameter vB is vector $b$. Function returns reference to the vector changed. Function 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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
std::cout << vx.solve_tran (ma, vb);
std::cout << vx * ma - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+1.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
solve_tran(const basic_srmatrix<TR>&,const basic_rvector<TR>&,TR&)
operator/(const basic_srmatrix<TR>&)const
Parameters
[in]mAsrmatrix $A$.
[in]vBrvector $b$.
Returns
Reference to changed calling vector.

Definition at line 4840 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector basic_rvector< TR >::operator/ ( const basic_srmatrix< TR > &  mA) const throw (cvmexception)
inline

Linear solver operator (transposed)

Returns solution $x$ of linear equation $A^T*x=b$ (which is equivalent to $x*A=b$) where parameter mA is square matrix $A$ and calling vector is $b$. This operator 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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
vx = vb / ma;
std::cout << vx * ma - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
solve_tran(const basic_srmatrix<TR>&,const basic_rvector<TR>&)
Parameters
[in]mAsrmatrix $A$.
Returns
Result object (solution of the equation).

Definition at line 4885 of file cvm.h.

template<typename TR>
basic_rvector basic_rvector< TR >::operator% ( const basic_srmatrix< TR > &  mA) const throw (cvmexception)
inline

Linear solver operator.

Returns solution $x$ of linear equation $A*x=b$ where parameter mA is square matrix $A$ and calling vector is $b$. This operator 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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b[] = {1., 2., 3.};
srmatrix ma(m, 3);
rvector vb(b, 3);
rvector vx(3);
vx = vb % ma;
std::cout << ma * vx - vb;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
solve(const basic_srmatrix<TR>&,const basic_rvector<TR>&)
Parameters
[in]mAsrmatrix $A$.
Returns
Result object (solution of the equation).

Definition at line 4925 of file cvm.h.

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

LU factorization based linear solver.

Sets calling vector to be equal to solution $x$ of 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 vB is vector $b$. Function returns reference to the vector 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 vectors $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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b1[] = {1., 2., 3.};
double b2[] = {0., -1., -2.};
srmatrix ma(m, 3);
srmatrix mLU(3);
rvector vb1(b1, 3);
rvector vb2(b2, 3);
rvector vx1(3);
rvector vx2(3);
iarray nPivots(3);
double dErr = 0.;
mLU.low_up(ma, nPivots);
std::cout << vx1.solve_lu (ma, mLU, nPivots, vb1, dErr);
std::cout << dErr << std::endl;
std::cout << vx2.solve_lu (ma, mLU, nPivots, vb2, dErr);
std::cout << dErr << std::endl;
std::cout << ma * vx1 - vb1 << ma * vx2 - vb2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+8.000000000000e+000 -8.000000000000e+000 +3.000000000000e+000
+6.661338147751e-015
-5.000000000000e+000 +4.000000000000e+000 -1.000000000000e+000
+5.329070518201e-015
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
srmatrix::low_up()
Parameters
[in]mAsrmatrix $A$.
[in]mLULU factorization of matrix $A$.
[in]pPivotspivots vector.
[in]vBrvector $b$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling vector.

Definition at line 4991 of file cvm.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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

LU factorization based linear solver.

Sets calling vector to be equal to solution $x$ of 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 vB is vector $b$. Function returns reference to the vector 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 vectors $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::showpos);
std::cout.precision (12);
try {
double m[] = {1., -1., 1., 2., -2., 1., 3., -2., 1.};
double b1[] = {1., 2., 3.};
double b2[] = {0., -1., -2.};
srmatrix ma(m, 3);
srmatrix mLU(3);
rvector vb1(b1, 3);
rvector vb2(b2, 3);
rvector vx1(3);
rvector vx2(3);
iarray nPivots(3);
mLU.low_up(ma, nPivots);
std::cout << vx1.solve_lu (ma, mLU, nPivots, vb1);
std::cout << vx2.solve_lu (ma, mLU, nPivots, vb2);
std::cout << ma * vx1 - vb1 << ma * vx2 - vb2;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+8.000000000000e+000 -8.000000000000e+000 +3.000000000000e+000
-5.000000000000e+000 +4.000000000000e+000 -1.000000000000e+000
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
+0.000000000000e+000 +0.000000000000e+000 +0.000000000000e+000
See Also
srmatrix::low_up()
Parameters
[in]mAsrmatrix $A$.
[in]mLULU factorization of matrix $A$.
[in]pPivotspivots vector.
[in]vBrvector $b$.
Returns
Reference to changed calling vector.

Definition at line 5056 of file cvm.h.

Here is the call graph for this function:

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

Overdetermined or underdetermined linear solver.

Solves 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$ and $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 sets calling object to be the solution and returns reference to it. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(7, 5);
rvector b(7), bt(5);
treal dErr;
a.randomize(-10., 10.);
b.randomize(-10., 10.);
bt.randomize(-10., 10.);
rvector x(5);
x.gels(false, a, b, dErr);
xt.gels(true, a, bt, dErr);
std::cout << (a.pinv()*b - x).norm() << std::endl;
std::cout << (~a.pinv()*bt - xt).norm() << std::endl;
prints
+5.1347815e-016
+1.1752774e-015
See Also
rmatrix::pinv()
Parameters
[in]transposeTrue to compute for transposed matrix $A$.
[in]mArmatrix $A$.
[in]vBrvector $b$.
[out]dErrNorm of computation error.
Returns
Reference to changed calling vector.

Definition at line 5117 of file cvm.h.

Here is the call graph for this function:

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

Linear least squares problem.

Computes minimum-norm solution to linear least squares problem

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

using complete orthogonal factorization of $m\times n$ 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 sets calling object to be the solution and returns reference to it. It throws cvmexception in case of inappropriate sizes of the operands.

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

Definition at line 5178 of file cvm.h.

Here is the call graph for this function:

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

Linear least squares problem.

Computes minimum-norm solution to linear least squares problem

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

using singular value decomposition of $m\times n$ 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. This function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. Internally function uses DGELSS LAPACK routines, see more details about the algorithm in that routine's documentation. Matrix $A$ is passed as argument mA. Function sets calling object to be the solution and returns reference to it. It throws cvmexception in case of inappropriate sizes of the operands.

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

Definition at line 5243 of file cvm.h.

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

Linear least squares problem.

Computes minimum-norm solution to linear least squares problem

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

using singular value decomposition of $m\times n$ 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. This function also computes singular values of $A$ in decreasing order and returns them in sv output parameter having $\min(m,n)$ size. Internally function uses DGELSD LAPACK routines, see more details about the algorithm in that routine's documentation. Matrix $A$ is passed as argument mA. Function sets calling object to be the solution and returns reference to it. It throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
rmatrix a(4, 5);
rvector b(4);
a.randomize(-10., 10.);
b.randomize(-10., 10.);
rvector sv(4);
rvector x(5);
tint rank;
x.gelsd(a, b, sv, rank);
std::cout << (a*x - b).norm() << std::endl;
std::cout << (sv - a.svd()).norm() << std::endl;
std::cout << rank << " " << a.rank() << std::endl;
prints
+7.8441794e-015
+5.1021966e-015
+4 +4
See Also
gelss()
gelsy()
rmatrix::gelsy()
rmatrix::rank()
Parameters
[in]mArmatrix $A$.
[in]vBrvector $b$.
[out]svSingular values of matrix $A$.
[out]rankRank of matrix $A$.
[in]tolRank computation tolerance.
Returns
Reference to changed calling vector.

Definition at line 5303 of file cvm.h.

template<typename TR>
basic_rvector& basic_rvector< TR >::svd ( const basic_rmatrix< TR > &  mA) throw (cvmexception)
inline

Singular value decomposition.

Sets calling vector to be equal to singular values

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

of $m\times n$ real matrix $A$ (parameter mA). 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 returns reference to the object it changes and throws cvmexception in case of inappropriate calling object size (it must be equal to $\min(m,n)$) or in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (10);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
rmatrix mSigma(4,3);
rvector v(3);
srmatrix mU(4), mVH(3);
v.svd(mA, 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.8425643615e-01 +1.9516809011e-01 +1.1506232201e-02 -8.5280286542e-01
+2.1685987119e-01 -3.4107922671e-01 -8.8948423927e-01 -2.1320071636e-01
+6.6237057295e-01 +7.1553688692e-01 -6.1787070600e-02 -2.1320071636e-01
-5.2889765022e-01 +5.7756501033e-01 -4.5262319054e-01 +4.2640143271e-01
-2.2124855498e-01 +8.5354150454e-01 -4.7171599183e-01
+9.5937301747e-01 +1.0365951763e-01 -2.6240830353e-01
-1.7507852602e-01 -5.1060905244e-01 -8.4179920723e-01
+4.9561500411e+00 +0.0000000000e+00 +0.0000000000e+00
+0.0000000000e+00 +2.5088408581e+00 +0.0000000000e+00
+0.0000000000e+00 +0.0000000000e+00 +3.7721919242e-01
+0.0000000000e+00 +0.0000000000e+00 +0.0000000000e+00
+1.3710111285e-15
+2.4829995848e-15
Parameters
[in]mArmatrix $A$.
Returns
Reference to changed calling vector.

Definition at line 5382 of file cvm.h.

template<typename TR>
basic_rvector& basic_rvector< TR >::svd ( const basic_cmatrix< TR, TC > &  mA) throw (cvmexception)
inline

Singular value decomposition.

Sets calling vector to be equal to singular values

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

of $m\times n$ complex matrix $A$ (parameter mA). 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 returns reference to the object it changes and throws cvmexception in case of inappropriate calling object size (it must be equal to $\min(m,n)$) or in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (10);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
rmatrix mSigma(4,3);
rvector v(3);
srmatrix mU(4), mVH(3);
v.svd(mA, 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.8425643615e-01 +1.9516809011e-01 +1.1506232201e-02 -8.5280286542e-01
+2.1685987119e-01 -3.4107922671e-01 -8.8948423927e-01 -2.1320071636e-01
+6.6237057295e-01 +7.1553688692e-01 -6.1787070600e-02 -2.1320071636e-01
-5.2889765022e-01 +5.7756501033e-01 -4.5262319054e-01 +4.2640143271e-01
-2.2124855498e-01 +8.5354150454e-01 -4.7171599183e-01
+9.5937301747e-01 +1.0365951763e-01 -2.6240830353e-01
-1.7507852602e-01 -5.1060905244e-01 -8.4179920723e-01
+4.9561500411e+00 +0.0000000000e+00 +0.0000000000e+00
+0.0000000000e+00 +2.5088408581e+00 +0.0000000000e+00
+0.0000000000e+00 +0.0000000000e+00 +3.7721919242e-01
+0.0000000000e+00 +0.0000000000e+00 +0.0000000000e+00
+1.3710111285e-15
+2.4829995848e-15
Parameters
[in]mAcmatrix $A$.
Returns
Reference to changed calling vector.

Definition at line 5460 of file cvm.h.

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

Singular value decomposition.

Sets calling vector to be equal to singular values

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

of $m\times n$ real matrix $A$ (parameter mA). 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 returns reference to the object it changes and 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::showpos);
std::cout.precision (10);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
rmatrix mSigma(4,3);
rvector v(3);
srmatrix mU(4), mVH(3);
v.svd(mA, 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.8425643615e-01 +1.9516809011e-01 +1.1506232201e-02 -8.5280286542e-01
+2.1685987119e-01 -3.4107922671e-01 -8.8948423927e-01 -2.1320071636e-01
+6.6237057295e-01 +7.1553688692e-01 -6.1787070600e-02 -2.1320071636e-01
-5.2889765022e-01 +5.7756501033e-01 -4.5262319054e-01 +4.2640143271e-01
-2.2124855498e-01 +8.5354150454e-01 -4.7171599183e-01
+9.5937301747e-01 +1.0365951763e-01 -2.6240830353e-01
-1.7507852602e-01 -5.1060905244e-01 -8.4179920723e-01
+4.9561500411e+00 +0.0000000000e+00 +0.0000000000e+00
+0.0000000000e+00 +2.5088408581e+00 +0.0000000000e+00
+0.0000000000e+00 +0.0000000000e+00 +3.7721919242e-01
+0.0000000000e+00 +0.0000000000e+00 +0.0000000000e+00
+1.3710111285e-15
+2.4829995848e-15
Parameters
[in]mArmatrix $A$.
[out]mUsrmatrix $U$.
[out]mVHsrmatrix $V^H$.
Returns
Reference to changed calling vector.

Definition at line 5543 of file cvm.h.

template<typename TR>
basic_rvector& basic_rvector< TR >::svd ( const basic_cmatrix< TR, TC > &  mA,
basic_scmatrix< TR, TC > &  mU,
basic_scmatrix< TR, TC > &  mVH 
) throw (cvmexception)
inline

Singular value decomposition.

Sets calling vector to be equal to singular values

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

of $m\times n$ complex matrix $A$ (parameter mA). 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 returns reference to the object it changes and 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::showpos);
std::cout.precision (10);
try {
double m[] = {1., -1., 1., 2., -2., 1.,
3., -2., 1., 0., -2., 1.};
rmatrix mA(m,4,3);
rmatrix mSigma(4,3);
rvector v(3);
srmatrix mU(4), mVH(3);
v.svd(mA, 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.8425643615e-01 +1.9516809011e-01 +1.1506232201e-02 -8.5280286542e-01
+2.1685987119e-01 -3.4107922671e-01 -8.8948423927e-01 -2.1320071636e-01
+6.6237057295e-01 +7.1553688692e-01 -6.1787070600e-02 -2.1320071636e-01
-5.2889765022e-01 +5.7756501033e-01 -4.5262319054e-01 +4.2640143271e-01
-2.2124855498e-01 +8.5354150454e-01 -4.7171599183e-01
+9.5937301747e-01 +1.0365951763e-01 -2.6240830353e-01
-1.7507852602e-01 -5.1060905244e-01 -8.4179920723e-01
+4.9561500411e+00 +0.0000000000e+00 +0.0000000000e+00
+0.0000000000e+00 +2.5088408581e+00 +0.0000000000e+00
+0.0000000000e+00 +0.0000000000e+00 +3.7721919242e-01
+0.0000000000e+00 +0.0000000000e+00 +0.0000000000e+00
+1.3710111285e-15
+2.4829995848e-15
Parameters
[in]mAcmatrix $A$.
[out]mUscmatrix $U$.
[out]mVHscmatrix $V^H$.
Returns
Reference to changed calling vector.

Definition at line 5627 of file cvm.h.

template<typename TR>
basic_rvector& basic_rvector< TR >::eig ( const basic_srsmatrix< TR > &  mA) throw (cvmexception)
inline

Eigenvalues.

Solves symmetric eigenvalue problem and sets calling vector to be equal to eigenvalues of symmetric matrix mA. The symmetric eigenvalue problem is defined as follows: given symmetric or Hermitian matrix $A$, find the eigenvalues $\lambda$ and the corresponding eigenvectors $z$ that satisfy the equation

\[ Az = \lambda z. \]

All $n$ eigenvalues are real not only for real symmetric but also for complex Hermitian matrices $A$, and there exists an orthogonal system of $n$ eigenvectors. If $A$ is symmetric or Hermitian positive-definite matrix, all eigenvalues are positive. Function returns reference to the vector changed and throws cvmexception in case of inappropriate calling object sizes or in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (3);
try {
srsmatrix m(3);
srmatrix me(3);
rvector v(3);
m.randomize(1., 3.);
v.eig (m, me);
std::cout << v;
std::cout << m * me(1) - me(1) * v(1);
std::cout << m * me(2) - me(2) * v(2);
std::cout << m * me(3) - me(3) * v(3);
std::cout << me(1) * me(2) << std::endl; // orthogonality check
schmatrix mc(3);
scmatrix mce(3);
mc.randomize_real(1., 3.);
mc.randomize_imag(1., 3.);
v.eig (mc, mce);
std::cout << v;
std::cout << mc * mce(1) - mce(1) * v(1);
std::cout << mc * mce(2) - mce(2) * v(2);
std::cout << mc * mce(3) - mce(3) * v(3);
std::cout << mce(1) % mce(2) << std::endl; // orthogonality check
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-9.360e-01 +3.535e-01 +6.376e+00
-4.441e-16 -5.551e-16 -6.106e-16
+3.331e-16 +1.145e-16 +1.110e-16
-4.441e-16 +0.000e+00 -4.441e-16
+2.060e-17
-3.274e+00 +9.710e-01 +8.209e+00
(-4.441e-16,-1.221e-15) (-1.443e-15,-4.441e-16) (-8.882e-16,+4.683e-16)
(-5.551e-16,-2.776e-16) (+0.000e+00,-4.025e-16) (+6.661e-16,-2.461e-17)
(-5.551e-16,+0.000e+00) (+4.441e-16,-4.441e-16) (+0.000e+00,+3.896e-16)
(+1.608e-16,-2.261e-17)
See Also
cvector::eig()
Parameters
[in]mAsrsmatrix $A$.
Returns
Reference to changed calling vector.

Definition at line 5706 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::eig ( const basic_srsmatrix< TR > &  mA,
basic_srmatrix< TR > &  mEigVect 
) throw (cvmexception)
inline

Eigenvalues.

Solves symmetric eigenvalue problem and sets calling vector to be equal to eigenvalues of symmetric matrix mA. The symmetric eigenvalue problem is defined as follows: given symmetric or Hermitian matrix $A$, find the eigenvalues $\lambda$ and the corresponding eigenvectors $z$ that satisfy the equation

\[ Az = \lambda z. \]

All $n$ eigenvalues are real not only for real symmetric but also for complex Hermitian matrices $A$, and there exists an orthogonal system of $n$ eigenvectors. If $A$ is symmetric or Hermitian positive-definite matrix, all eigenvalues are positive. Function returns reference to the vector changed and throws cvmexception in case of inappropriate calling object sizes or in case of convergence error. It sets output parameter mEigVect to be equal to square matrix containing eigenvectors as columns.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (3);
try {
srsmatrix m(3);
srmatrix me(3);
rvector v(3);
m.randomize(1., 3.);
v.eig (m, me);
std::cout << v;
std::cout << m * me(1) - me(1) * v(1);
std::cout << m * me(2) - me(2) * v(2);
std::cout << m * me(3) - me(3) * v(3);
std::cout << me(1) * me(2) << std::endl; // orthogonality check
schmatrix mc(3);
scmatrix mce(3);
mc.randomize_real(1., 3.);
mc.randomize_imag(1., 3.);
v.eig (mc, mce);
std::cout << v;
std::cout << mc * mce(1) - mce(1) * v(1);
std::cout << mc * mce(2) - mce(2) * v(2);
std::cout << mc * mce(3) - mce(3) * v(3);
std::cout << mce(1) % mce(2) << std::endl; // orthogonality check
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-9.360e-01 +3.535e-01 +6.376e+00
-4.441e-16 -5.551e-16 -6.106e-16
+3.331e-16 +1.145e-16 +1.110e-16
-4.441e-16 +0.000e+00 -4.441e-16
+2.060e-17
-3.274e+00 +9.710e-01 +8.209e+00
(-4.441e-16,-1.221e-15) (-1.443e-15,-4.441e-16) (-8.882e-16,+4.683e-16)
(-5.551e-16,-2.776e-16) (+0.000e+00,-4.025e-16) (+6.661e-16,-2.461e-17)
(-5.551e-16,+0.000e+00) (+4.441e-16,-4.441e-16) (+0.000e+00,+3.896e-16)
(+1.608e-16,-2.261e-17)
See Also
cvector::eig()
Parameters
[in]mAsrsmatrix $A$.
[out]mEigVectsrmatrix of eigenvectors (as columns).
Returns
Reference to changed calling vector.

Definition at line 5786 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::eig ( const basic_schmatrix< TR, TC > &  mA) throw (cvmexception)
inline

Eigenvalues.

Solves symmetric eigenvalue problem and sets calling vector to be equal to eigenvalues of hermitian matrix mA. The symmetric eigenvalue problem is defined as follows: given symmetric or Hermitian matrix $A$, find the eigenvalues $\lambda$ and the corresponding eigenvectors $z$ that satisfy the equation

\[ Az = \lambda z. \]

All $n$ eigenvalues are real not only for real symmetric but also for complex Hermitian matrices $A$, and there exists an orthogonal system of $n$ eigenvectors. If $A$ is symmetric or Hermitian positive-definite matrix, all eigenvalues are positive. Function returns reference to the vector changed and throws cvmexception in case of inappropriate calling object sizes or in case of convergence error.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (3);
try {
srsmatrix m(3);
srmatrix me(3);
rvector v(3);
m.randomize(1., 3.);
v.eig (m, me);
std::cout << v;
std::cout << m * me(1) - me(1) * v(1);
std::cout << m * me(2) - me(2) * v(2);
std::cout << m * me(3) - me(3) * v(3);
std::cout << me(1) * me(2) << std::endl; // orthogonality check
schmatrix mc(3);
scmatrix mce(3);
mc.randomize_real(1., 3.);
mc.randomize_imag(1., 3.);
v.eig (mc, mce);
std::cout << v;
std::cout << mc * mce(1) - mce(1) * v(1);
std::cout << mc * mce(2) - mce(2) * v(2);
std::cout << mc * mce(3) - mce(3) * v(3);
std::cout << mce(1) % mce(2) << std::endl; // orthogonality check
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-9.360e-01 +3.535e-01 +6.376e+00
-4.441e-16 -5.551e-16 -6.106e-16
+3.331e-16 +1.145e-16 +1.110e-16
-4.441e-16 +0.000e+00 -4.441e-16
+2.060e-17
-3.274e+00 +9.710e-01 +8.209e+00
(-4.441e-16,-1.221e-15) (-1.443e-15,-4.441e-16) (-8.882e-16,+4.683e-16)
(-5.551e-16,-2.776e-16) (+0.000e+00,-4.025e-16) (+6.661e-16,-2.461e-17)
(-5.551e-16,+0.000e+00) (+4.441e-16,-4.441e-16) (+0.000e+00,+3.896e-16)
(+1.608e-16,-2.261e-17)
See Also
cvector::eig()
Parameters
[in]mAschmatrix $A$.
Returns
Reference to changed calling vector.

Definition at line 5866 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::eig ( const basic_schmatrix< TR, TC > &  mA,
basic_scmatrix< TR, TC > &  mEigVect 
) throw (cvmexception)
inline

Eigenvalues.

Solves symmetric eigenvalue problem and sets calling vector to be equal to eigenvalues of hermitian matrix mA. The symmetric eigenvalue problem is defined as follows: given symmetric or Hermitian matrix $A$, find the eigenvalues $\lambda$ and the corresponding eigenvectors $z$ that satisfy the equation

\[ Az = \lambda z. \]

All $n$ eigenvalues are real not only for real symmetric but also for complex Hermitian matrices $A$, and there exists an orthogonal system of $n$ eigenvectors. If $A$ is symmetric or Hermitian positive-definite matrix, all eigenvalues are positive. Function returns reference to the vector changed and throws cvmexception in case of inappropriate calling object sizes or in case of convergence error. It sets output parameter mEigVect to be equal to square matrix containing eigenvectors as columns. Example:

using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (3);
try {
srsmatrix m(3);
srmatrix me(3);
rvector v(3);
m.randomize(1., 3.);
v.eig (m, me);
std::cout << v;
std::cout << m * me(1) - me(1) * v(1);
std::cout << m * me(2) - me(2) * v(2);
std::cout << m * me(3) - me(3) * v(3);
std::cout << me(1) * me(2) << std::endl; // orthogonality check
schmatrix mc(3);
scmatrix mce(3);
mc.randomize_real(1., 3.);
mc.randomize_imag(1., 3.);
v.eig (mc, mce);
std::cout << v;
std::cout << mc * mce(1) - mce(1) * v(1);
std::cout << mc * mce(2) - mce(2) * v(2);
std::cout << mc * mce(3) - mce(3) * v(3);
std::cout << mce(1) % mce(2) << std::endl; // orthogonality check
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}

prints

-9.360e-01 +3.535e-01 +6.376e+00
-4.441e-16 -5.551e-16 -6.106e-16
+3.331e-16 +1.145e-16 +1.110e-16
-4.441e-16 +0.000e+00 -4.441e-16
+2.060e-17
-3.274e+00 +9.710e-01 +8.209e+00
(-4.441e-16,-1.221e-15) (-1.443e-15,-4.441e-16) (-8.882e-16,+4.683e-16)
(-5.551e-16,-2.776e-16) (+0.000e+00,-4.025e-16) (+6.661e-16,-2.461e-17)
(-5.551e-16,+0.000e+00) (+4.441e-16,-4.441e-16) (+0.000e+00,+3.896e-16)
(+1.608e-16,-2.261e-17)
See Also
cvector::eig()
Parameters
[in]mAschmatrix $A$.
[out]mEigVectscmatrix of eigenvectors (as columns).
Returns
Reference to changed calling vector.

Definition at line 5946 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::gemv ( bool  bLeft,
const basic_rmatrix< TR > &  m,
TR  dAlpha,
const basic_rvector< TR > &  v,
TR  dBeta 
) throw (cvmexception)
inline

Generic matrix-vector operation.

Calls one of DGEMV routines of the BLAS Library performing matrix-vector operation defined as

\[ c=\alpha\,M\cdot v + \beta\,c\quad\text{or}\quad c=\alpha\,v\cdot M + \beta\, c, \]

where $\alpha$ and $\beta$ are real numbers (parameters dAlpha and dBeta), $M$ is matrix (parameter m) and $v$ and $c$ are vectors (parameter v and calling vector respectively). First operation is performed if bLeft passed is false and second one otherwise. Function returns reference to the vector changed and throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (7);
try {
double alpha = 1.3;
double beta = -0.7;
rmatrix m(4,3);
rvector c(4);
rvector v(3);
m.randomize(-1., 2.); v.randomize(-1., 3.); c.randomize(0., 2.);
std::cout << m * v * alpha + c * beta;
std::cout << c.gemv(false, m, alpha, v, beta);
std::cout << c * m * alpha + v * beta;
std::cout << v.gemv(true, m, alpha, c, beta);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
-3.5397829e-02 +3.1990410e-02 +3.2633344e-01 -5.4669713e-01
-3.5397829e-02 +3.1990410e-02 +3.2633344e-01 -5.4669713e-01
-4.7697026e-01 -2.2544922e-01 -5.5204984e-01
-4.7697026e-01 -2.2544922e-01 -5.5204984e-01
See Also
http://www.netlib.org/blas
Parameters
[in]bLeftIs left-sided multiplication.
[in]mrmatrix $M$.
[in]dAlphaNumber $\alpha$.
[in]vrvector $v$.
[in]dBetaNumber $\beta$.
Returns
Reference to changed calling vector.

Definition at line 6008 of file cvm.h.

Here is the call graph for this function:

template<typename TR>
basic_rvector& basic_rvector< TR >::gbmv ( bool  bLeft,
const basic_srbmatrix< TR > &  m,
TR  dAlpha,
const basic_rvector< TR > &  v,
TR  dBeta 
) throw (cvmexception)
inline

Generic band matrix-vector operation.

Calls one of DGBMV routines of the BLAS Library performing matrix-vector operation defined as

\[ c=\alpha\,M\cdot v + \beta\,c\quad\text{or}\quad c=\alpha\,v\cdot M + \beta\, c, \]

where $\alpha$ and $\beta$ are real numbers (parameters dAlpha and dBeta), $M$ is band matrix (parameter m) and $v$ and $c$ are vectors (parameter v and calling vector respectively). First operation is performed if bLeft passed is false and second one otherwise. Function returns reference to the vector changed and throws cvmexception in case of inappropriate sizes of the operands.

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::showpos);
std::cout.precision (7);
try {
double alpha = 1.3;
double beta = -0.7;
srbmatrix m(3, 1, 0);
rvector c(3);
rvector v(3);
m.randomize(-1., 2.); v.randomize(-1., 3.); c.randomize(0., 2.);
std::cout << m * v * alpha + c * beta;
std::cout << c.gbmv(false, m, alpha, v, beta);
std::cout << c * m * alpha + v * beta;
std::cout << v.gbmv(true, m, alpha, c, beta);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
+1.4551599e+00 -5.1882508e-01 -5.2088503e-02
+1.4551599e+00 -5.1882508e-01 -5.2088503e-02
+7.3471591e-01 -2.6952064e-01 -2.0478054e-01
+7.3471591e-01 -2.6952064e-01 -2.0478054e-01
See Also
http://www.netlib.org/blas
Parameters
[in]bLeftIs left-sided multiplication.
[in]msrbmatrix $M$.
[in]dAlphaNumber $\alpha$.
[in]vrvector $v$.
[in]dBetaNumber $\beta$.
Returns
Reference to changed calling vector.

Definition at line 6068 of file cvm.h.

Here is the call graph for this function:

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

Randomizer.

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

Example:
using namespace cvm;
std::cout.setf (std::ios::scientific | std::ios::left);
std::cout.precision (7);
rvector v(4);
v.randomize(-2.,3.);
std::cout << v;
prints
-1.1160314e+000 2.5649586e+000 8.9345988e-001 -1.1631825e+000
Parameters
[in]dFromFirst limit.
[in]dToSecond limit.
Returns
Reference to changed calling vector.

Definition at line 6099 of file cvm.h.

Here is the call graph for this function:


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