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 | Protected Types | Friends | List of all members
basic_fvector< T > Class Template Reference

Vector of functions class. More...

#include <cfun.h>

Inheritance diagram for basic_fvector< T >:
Inheritance graph
[legend]
Collaboration diagram for basic_fvector< T >:
Collaboration graph
[legend]

Public Member Functions

 basic_fvector ()
 Default constructor.
 basic_fvector (size_t nSize)
 Constructor.
 basic_fvector (const string_array &saInput)
 Constructor.
 basic_fvector (const string_array &saVars, const string_array &saBodies, const string_array &saParameters, const string_array &saMeanings)
 Constructor.
 basic_fvector (const basic_fvector &fv)
 Copy Constructor.
 basic_fvector (basic_fvector &&fv)
 Move Constructor.
basic_fvectoroperator= (const basic_fvector &fv) throw (cvmexception)
 Assignment operator.
basic_fvectoroperator= (basic_fvector &&fv) throw (cvmexception)
 Move sssignment operator.
bool operator== (const basic_fvector &fv) const
 Vectors of functions comparison.
bool operator!= (const basic_fvector &fv) const
 Vectors of functions comparison.
basic_fvectoroperator<< (const basic_fvector &fv)
 Replacement operator.
basic_fvector drv (size_t nVarNum) const
 Partial derivative.
basic_fvectorsimp ()
 Simplifier.
basic_fvector operator+ (const basic_fvector &fv) const throw (cvmexception)
 Addition operator.
basic_fvector operator- (const basic_fvector &fv) const throw (cvmexception)
 Subtraction operator.
basic_fvectoroperator+= (const basic_fvector &fv) throw (cvmexception)
 Increment operator.
basic_fvectoroperator-= (const basic_fvector &fv) throw (cvmexception)
 Decrement operator.
basic_fvector operator* (const BaseFunction &f) const
 Multiplication operator.
basic_fvector operator/ (const BaseFunction &f) const
 Division operator.
basic_fvector operator* (const T &d) const
 Multiplication operator.
basic_fvector operator/ (const T &d) const
 Division operator.
basic_fvectoroperator*= (const BaseFunction &f)
 Multiply and assign operator.
basic_fvectoroperator/= (const BaseFunction &f)
 Divide and assign operator.
basic_fvectoroperator*= (const T &d)
 Multiply and assign operator.
basic_fvectoroperator/= (const T &d)
 Divide and assign operator.
BaseFunction operator* (const basic_fvector &fv) const throw (cvmexception)
 Scalar product.
basic_fvector operator* (const basic_fmatrix< T > &fm) const throw (cvmexception)
 Vector by matrix product.
basic_fvectormult (const basic_fvector &fv, const basic_fmatrix< T > &fm) throw (cvmexception)
 Vector by matrix product.
basic_fvectormult (const basic_fmatrix< T > &fm, const basic_fvector &fv) throw (cvmexception)
 Matrix by vector product
basic_fmatrix< T > jacobian (size_t nfrom=0, size_t vars=0) const
 Jacobi matrix.
void jacobian (basic_fmatrix< T > &fmj, size_t nfrom=0, size_t vars=0) const
 Jacobi matrix.
- Public Member Functions inherited from FArray< T >
 FArray ()
 Default constructor.
 FArray (size_t nSize)
 Constructor.
 FArray (const FArray &a)
 Copy constructor.
 FArray (FArray &&a)
 Move constructor.
 FArray (const string_array &saInput)
 Constructor.
 FArray (const string_array &saVars, const string_array &saBodies, const string_array &saParameters, const string_array &saMeanings)
 Constructor.
virtual ~FArray ()
 Destructor.
std::vector< BaseFunction > & impl ()
 Internal storage.
const std::vector< BaseFunction > & impl () const
 Internal storage.
size_t size () const
 Internal storage.
const BaseFunctionoperator[] (size_t n) const
 Constant reference to element (not l-value, zero-based)
BaseFunctionoperator[] (size_t n)
 Reference to element (l-value, zero-based)
void value (T *pv) const
 Numerical value.
void value (T d, T *pv) const
 Numerical value.
void value (T d1, T d2, T *pv) const
 Numerical value.
void value (T d1, T d2, T d3, T *pv) const
 Numerical value.
void value (const T *pd, T *pv) const
 Numerical value.

Protected Types

typedef FArray< T > BaseFArray
 Base class.
typedef BaseFArray::BaseFunction BaseFunction
 Vector element, i.e. rfunction or cfunction.
- Protected Types inherited from FArray< T >
typedef basic_function< T > BaseFunction
 Vector element, i.e. rfunction or cfunction.

Friends

class basic_fmatrix< T >
std::ostream & operator<< (std::ostream &os, const basic_fvector< T > &fv)
 Output operator.

Additional Inherited Members

- Protected Attributes inherited from FArray< T >
std::vector< BaseFunctionmv
 Internal storage.

Detailed Description

template<typename T>
class basic_fvector< T >

Vector of functions class.

T type stands for treal or tcomplex. Please use rfvector and cfvector classes in your applications.

See Also
rfvector
cfvector
basic_fmatrix

Definition at line 7939 of file cfun.h.

Member Typedef Documentation

template<typename T>
typedef FArray<T> basic_fvector< T >::BaseFArray
protected

Base class.

Definition at line 7944 of file cfun.h.

template<typename T>
typedef BaseFArray::BaseFunction basic_fvector< T >::BaseFunction
protected

Vector element, i.e. rfunction or cfunction.

Definition at line 7945 of file cfun.h.

Constructor & Destructor Documentation

template<typename T>
basic_fvector< T >::basic_fvector ( )
inline

Default constructor.

Creates empty vector of functions. No memory gets allocated.

Definition at line 7960 of file cfun.h.

template<typename T>
basic_fvector< T >::basic_fvector ( size_t  nSize)
inlineexplicit

Constructor.

Creates vector of zero functions of nSize size.

Example:
using namespace cvm;
rfvector rfv(3);
std::cout << rfv;
cfvector cfv(3);
std::cout << cfv;
prints
0 0 0
(0,0) (0,0) (0,0)
Parameters
[in]nSizeNumber of functions in array.

Definition at line 7984 of file cfun.h.

template<typename T>
basic_fvector< T >::basic_fvector ( const string_array saInput)
inlineexplicit

Constructor.

Creates vector of functions of saInput.size() size. Each function element is ininialized using appropriate string as parameterless input in Wolfram's Mathemaca syntax {var1[,var2,...]} expr

Example:
using namespace cvm;
using namespace std;
funcs.push_back("{x} x");
funcs.push_back("{x} x^2");
funcs.push_back("{x} x^3");
rfvector rfv(funcs);
cfvector cfv(funcs);
rvector rx(1), ry(3);
cvector cx(1), cy(3);
rx(1) = 2.;
cx(1) = complex<double>(2.,0.);
rfv.value(rx, ry);
cfv.value(cx, cy);
std::cout << rfv << ry << std::endl;
std::cout << cfv << cy << std::endl;
prints
{x} x {x} x^2 {x} x^3
2 4 8
{x} x {x} x^(2,0) {x} x^(3,0)
(2,0) (4,0) (8,0)
Parameters
[in]saInputArray of strings.

Definition at line 8025 of file cfun.h.

template<typename T>
basic_fvector< T >::basic_fvector ( const string_array saVars,
const string_array saBodies,
const string_array saParameters,
const string_array saMeanings 
)
inline

Constructor.

Creates vector of parameterized functions of one or more variables. Throws cvmexception in case of syntax or memory allocation error.

Example:
using namespace cvm;
using namespace std;
try{
string_array vars, bodies, params, meanings;
vars.push_back("x");
vars.push_back("y");
params.push_back("p");
meanings.push_back("sqrt(x) + sqrt(y)");
bodies.push_back("p^2");
bodies.push_back("p");
bodies.push_back("x+y");
rfvector rfv(vars, bodies, params, meanings);
rvector rv(3);
rfv.value(4., 1., rv);
std::cout << rfv << rv;
cfvector cfv(vars, bodies, params, meanings);
cvector cv(3);
cfv.value(complex<double>(4., 0.), complex<double>(1., 0.), cv);
std::cout << cfv << cv;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} (sqrt(x)+sqrt(y))^2 {x,y} sqrt(x)+sqrt(y) {x,y} x+y
9 3 5
{x,y} (sqrt(x)+sqrt(y))^(2,0) {x,y} sqrt(x)+sqrt(y) {x,y} x+y
(9,0) (3,0) (5,0)
Parameters
[in]saVarsString array with variables (may be empty).
[in]saBodiesString array with functions' expressions. For expression syntax look at basic_function description.
[in]saParametersString array with parameters (may be empty).
[in]saMeaningsString array with parameters' meanings (may be empty, must have the same size as saParameters).

Definition at line 8075 of file cfun.h.

template<typename T>
basic_fvector< T >::basic_fvector ( const basic_fvector< T > &  fv)
inline

Copy Constructor.

Creates copy of vector of functions referred by fv.

Parameters
[in]fvVector of functions (rfvector or cfvector) to copy from.

Definition at line 8087 of file cfun.h.

template<typename T>
basic_fvector< T >::basic_fvector ( basic_fvector< T > &&  fv)
inline

Move Constructor.

Definition at line 8095 of file cfun.h.

Member Function Documentation

template<typename T>
basic_fvector& basic_fvector< T >::operator= ( const basic_fvector< T > &  fv) throw (cvmexception)
inline

Assignment operator.

Assigns basic_fvector object to calling one or throws cvmexception if objects have different sizes.

Example:
using namespace cvm;
using namespace std;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfvector rfv2(3);
cfvector cfv2(3);
rfv2 = rfv;
cfv2 = cfv;
std::cout << rfv2 << cfv2;
prints
{x,y} x+y+1 {x,y} x*y {x,y} x^y
{x,y} x+y+(1,0) {x,y} x*y {x,y} x^y
Parameters
[in]fvConst reference to vector of functions to assign.
Returns
Reference to changed calling vector.

Definition at line 8130 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator= ( basic_fvector< T > &&  fv) throw (cvmexception)
inline

Move sssignment operator.

Definition at line 8140 of file cfun.h.

template<typename T>
bool basic_fvector< T >::operator== ( const basic_fvector< T > &  fv) const
inline

Vectors of functions comparison.

Returns true if vectors of functions are equal and false otherwise.

Example:
using namespace cvm;
using namespace std;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfvector rfv2(3);
cfvector cfv2(3);
std::cout << (rfv2 == rfv) << std::endl;
std::cout << (cfv2 == cfv) << std::endl;
rfv2 = rfv;
cfv2 = cfv;
std::cout << (rfv2 == rfv) << std::endl;
std::cout << (cfv2 == cfv) << std::endl;
prints
0
0
1
1
Parameters
[in]fvConst reference to vector of functions to compare with.
Returns
boolean value.

Definition at line 8180 of file cfun.h.

template<typename T>
bool basic_fvector< T >::operator!= ( const basic_fvector< T > &  fv) const
inline

Vectors of functions comparison.

Returns true if vectors of functions are not equal and false otherwise.

Example:
using namespace cvm;
using namespace std;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfvector rfv2(3);
cfvector cfv2(3);
std::cout << (rfv2 != rfv) << std::endl;
std::cout << (cfv2 != cfv) << std::endl;
rfv2 = rfv;
cfv2 = cfv;
std::cout << (rfv2 != rfv) << std::endl;
std::cout << (cfv2 != cfv) << std::endl;
prints
1
1
0
0
Parameters
[in]fvConst reference to vector of functions to compare with.
Returns
boolean value.

Definition at line 8217 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator<< ( const basic_fvector< T > &  fv)
inline

Replacement operator.

Assigns basic_fvector object to calling one without checking anything.

Example:
using namespace cvm;
using namespace std;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfvector rfv2;
cfvector cfv2;
rfv2 << rfv;
cfv2 << cfv;
std::cout << rfv2 << cfv2;
prints
{x,y} x+y+1 {x,y} x*y {x,y} x^y
{x,y} x+y+(1,0) {x,y} x*y {x,y} x^y
Parameters
[in]fvConst reference to vector of functions to replace by.
Returns
Reference to changed calling vector.

Definition at line 8250 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::drv ( size_t  nVarNum) const
inline

Partial derivative.

Creates basic_fvector object as a partial derivative of calling vector. Variables set remains the same even if the derivative doesn't depend on some of them. Partial derivative is computed by nVarNum's variable (0-based, 0 by default).

Example:
using namespace cvm;
funcs.push_back("{x,y} x + log(x) + x^y");
funcs.push_back("{x,y} sin(x)*cos(y) + sin(y)*cos(x) + x*y");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv.drv(0) << rfv.drv(1);
std::cout << cfv.drv(0) << cfv.drv(1);
prints
{x,y} 1+1/x+y*x^(y-1) {x,y} cos(x)*cos(y)-sin(x)*sin(y)+y
{x,y} x^y*log(x) {x,y} cos(y)*cos(x)-sin(y)*sin(x)+x
{x,y} (1,0)+(1,0)/x+y*x^(y-(1,-0)) {x,y} cos(x)*cos(y)-sin(x)*sin(y)+y
{x,y} x^y*log(x) {x,y} cos(y)*cos(x)-sin(y)*sin(x)+x
Parameters
[in]nVarNumVariable's index (0-based, 0 by default).
Returns
Vector of functions object.

Definition at line 8285 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::simp ( )
inline

Simplifier.

Simplifies basic_fvector for fatsest numerical computation possible and returns reference to the object changed.

Example:
using namespace cvm;
funcs.push_back("{x,y} x*2 + 3*x");
funcs.push_back("{x,y} x + y + x + y + x");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv.simp() << cfv.simp();
prints
{x,y} x*5 {x,y} 2*(y+x)+x
{x,y} x*(5,0) {x,y} (2,0)*(y+x)+x
Returns
Reference to changed calling vector.

Definition at line 8314 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator+ ( const basic_fvector< T > &  fv) const throw (cvmexception)
inline

Addition operator.

Creates basic_fvector object as sum of calling vector and vector referred by fv. Operator throws cvmexception if sizes of vectors or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} y");
funcs2.push_back("{x,y} x * y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfvector rfv2(funcs2);
cfvector cfv2(funcs2);
std::cout << (rfv1 + rfv2);
std::cout << (cfv1 + cfv2);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x+y {x,y} x+y+x*y
{x,y} x+y {x,y} x+y+x*y
Parameters
[in]fvConst reference to vector to add.
Returns
Vector of functions object.

Definition at line 8354 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator- ( const basic_fvector< T > &  fv) const throw (cvmexception)
inline

Subtraction operator.

Creates basic_fvector object as difference of calling vector and vector referred by fv. Operator throws cvmexception if sizes of vectors or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} y");
funcs2.push_back("{x,y} x * y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfvector rfv2(funcs2);
cfvector cfv2(funcs2);
std::cout << (rfv1 - rfv2);
std::cout << (cfv1 - cfv2);
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x-y {x,y} x+y-x*y
{x,y} x-y {x,y} x+y-x*y
Parameters
[in]fvConst reference to vector to subtract.
Returns
Vector of functions object.

Definition at line 8396 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator+= ( const basic_fvector< T > &  fv) throw (cvmexception)
inline

Increment operator.

Adds to calling basic_fvector vector of functions referred by fv and returns reference to the object changed. Operator throws cvmexception if sizes of vectors or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} y");
funcs2.push_back("{x,y} x * y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfvector rfv2(funcs2);
cfvector cfv2(funcs2);
rfv1 += rfv2;
cfv1 += cfv2;
std::cout << rfv1;
std::cout << cfv1;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x+y {x,y} x+y+x*y
{x,y} x+y {x,y} x+y+x*y
Parameters
[in]fvConst reference to vector to add.
Returns
Reference to changed calling vector.

Definition at line 8441 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator-= ( const basic_fvector< T > &  fv) throw (cvmexception)
inline

Decrement operator.

Subtracts from calling basic_fvector vector of functions referred by fv and returns reference to the object changed. Operator throws cvmexception if sizes of vectors or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} y");
funcs2.push_back("{x,y} x * y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfvector rfv2(funcs2);
cfvector cfv2(funcs2);
rfv1 -= rfv2;
cfv1 -= cfv2;
std::cout << rfv1;
std::cout << cfv1;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x-y {x,y} x+y-x*y
{x,y} x-y {x,y} x+y-x*y
Parameters
[in]fvConst reference to vector to add.
Returns
Reference to changed calling vector.

Definition at line 8485 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator* ( const BaseFunction f) const
inline

Multiplication operator.

Creates basic_fvector object as product of calling vector and function referred by f. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
std::cout << rfv * rf << (rfv * rf).simp();
std::cout << cfv * cf << (cfv * cf).simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)*x/2 {x} 2*x*x/2
{x} (x+x^2)*x/2 {x} x^2
{x} (x+x^(2,0))*x/(2,0) {x} (2,0)*x*x/(2,0)
{x} (x+x^(2,0))*x/(2,0) {x} x^(2,0)
Parameters
[in]fConst reference to function to multiply by.
Returns
Vector of functions object.

Definition at line 8526 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator/ ( const BaseFunction f) const
inline

Division operator.

Creates basic_fvector object as division of calling vector by function referred by f. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
std::cout << rfv / rf << (rfv / rf).simp();
std::cout << cfv / cf << (cfv / cf).simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)/(x/2) {x} 2*x/(x/2)
{x} (x+x^2)*2/x {x} 4
{x} (x+x^(2,0))/(x/(2,0)) {x} (2,0)*x/(x/(2,0))
{x} (x+x^(2,0))*(2,0)/x {x} (4,0)
Parameters
[in]fConst reference to function to divide by.
Returns
Vector of functions object.

Definition at line 8567 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator* ( const T &  d) const
inline

Multiplication operator.

Creates basic_fvector object as product of calling vector and real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
try{
string_array funcs;
funcs.push_back("{x} x / 2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv * 2. << (rfv * 2.).simp();
std::cout << cfv * complex<double>(2., 0.) << (cfv * complex<double>(2., 0.)).simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} x/2*2 {x} 2*x*2
{x} x {x} 4*x
{x} x/(2,0)*(2,0) {x} (2,0)*x*(2,0)
{x} x {x} (4,0)*x
Parameters
[in]dNumber to multiply by.
Returns
Vector of functions object.

Definition at line 8606 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator/ ( const T &  d) const
inline

Division operator.

Creates basic_fvector object as division of calling vector by real or complex number referred by d.

Example:
using namespace cvm;
using namespace std;
try{
string_array funcs;
funcs.push_back("{x} x / 2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv / 2. << (rfv / 2.).simp();
std::cout << cfv / complex<double>(2., 0.) << (cfv / complex<double>(2., 0.)).simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x/2)/2 {x} 2*x/2
{x} x/4 {x} x
{x} (x/(2,0))/(2,0) {x} (2,0)*x/(2,0)
{x} x/(4,0) {x} x
Parameters
[in]dNumber to divide by.
Returns
Vector of functions object.

Definition at line 8645 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator*= ( const BaseFunction f)
inline

Multiply and assign operator.

Multiplies calling vector of functions by function referred by f and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
rfv *= rf;
cfv *= cf;
std::cout << rfv;
std::cout << rfv.simp();
std::cout << cfv;
std::cout << cfv.simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)*x/2 {x} 2*x*x/2
{x} (x+x^2)*x/2 {x} x^2
{x} (x+x^(2,0))*x/(2,0) {x} (2,0)*x*x/(2,0)
{x} (x+x^(2,0))*x/(2,0) {x} x^(2,0)
Parameters
[in]fConst reference to function to multiply by.
Returns
Reference to changed calling vector.

Definition at line 8691 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator/= ( const BaseFunction f)
inline

Divide and assign operator.

Divides calling vector of functions by function referred by f and returns reference to the object changed. Operator throws cvmexception if lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
rfv /= rf;
cfv /= cf;
std::cout << rfv;
std::cout << rfv.simp();
std::cout << cfv;
std::cout << cfv.simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)/(x/2) {x} 2*x/(x/2)
{x} (x+x^2)*2/x {x} 4
{x} (x+x^(2,0))/(x/(2,0)) {x} (2,0)*x/(x/(2,0))
{x} (x+x^(2,0))*(2,0)/x {x} (4,0)
Parameters
[in]fConst reference to function to divide by.
Returns
Reference to changed calling vector.

Definition at line 8736 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator*= ( const T &  d)
inline

Multiply and assign operator.

Multiplies calling vector of functions by real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
rfv *= 2.;
cfv *= 2.;
std::cout << rfv;
std::cout << rfv.simp();
std::cout << cfv;
std::cout << cfv.simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)*2 {x} 2*x*2
{x} (x+x^2)*2 {x} 4*x
{x} (x+x^(2,0))*(2,0) {x} (2,0)*x*(2,0)
{x} (x+x^(2,0))*(2,0) {x} (4,0)*x
Parameters
[in]dNumber to multiply by.
Returns
Reference to changed calling vector.

Definition at line 8780 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::operator/= ( const T &  d)
inline

Divide and assign operator.

Divides calling vector of functions by real or complex number referred by d and returns reference to the object changed.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x} x + x^2");
funcs.push_back("{x} 2 * x");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfunction rf("{x} x/2");
cfunction cf("{x} x/2");
rfv /= 2.;
cfv /= 2.;
std::cout << rfv;
std::cout << rfv.simp();
std::cout << cfv;
std::cout << cfv.simp();
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x} (x+x^2)/2 {x} 2*x/2
{x} (x+x^2)/2 {x} x
{x} (x+x^(2,0))/(2,0) {x} (2,0)*x/(2,0)
{x} (x+x^(2,0))/(2,0) {x} x
Parameters
[in]dNumber to divide by.
Returns
Reference to changed calling vector.

Definition at line 8824 of file cfun.h.

template<typename T>
BaseFunction basic_fvector< T >::operator* ( const basic_fvector< T > &  fv) const throw (cvmexception)
inline

Scalar product.

Creates basic_function object as scalar product of calling vector and vector referred by fv. Operator throws cvmexception if sizes of vectors or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} y");
funcs2.push_back("{x,y} x * y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfvector rfv2(funcs2);
cfvector cfv2(funcs2);
rfunction rf = rfv1 * rfv2;
cfunction cf = cfv1 * cfv2;
std::cout << rf << std::endl;
std::cout << cf << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x*y*(x+y+1)
{x,y} x*y*(x+y+(1,0))
Parameters
[in]fvVector of functions to multiply by.
Returns
basic_function object.

Definition at line 8866 of file cfun.h.

template<typename T>
basic_fvector basic_fvector< T >::operator* ( const basic_fmatrix< T > &  fm) const throw (cvmexception)
inline

Vector by matrix product.

Creates basic_fvector object as product of calling vector and matrix of functions referred by fm. Operator throws cvmexception if sizes of objects or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} x");
funcs2.push_back("{x,y} 1");
funcs2.push_back("{x,y} 1");
funcs2.push_back("{x,y} y");
rfvector rfv(funcs1);
cfvector cfv(funcs1);
rfmatrix rfm(2,2,funcs2);
cfmatrix cfm(2,2,funcs2);
std::cout << rfm << std::endl;
std::cout << rfv * rfm << std::endl;
std::cout << cfm << std::endl;
std::cout << cfv * cfm << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x {x,y} 1
{x,y} 1 {x,y} y
{x,y} x^2+x+y {x,y} x+(x+y)*y
{x,y} x {x,y} (1,0)
{x,y} (1,0) {x,y} y
{x,y} x^(2,0)+x+y {x,y} x+(x+y)*y
Parameters
[in]fmMatrix of functions to multiply by.
Returns
Vector of functions.

Definition at line 8919 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::mult ( const basic_fvector< T > &  fv,
const basic_fmatrix< T > &  fm 
) throw (cvmexception)
inline

Vector by matrix product.

Sets basic_fvector object to be equal to product of vector of functions referred by fv and matrix of functions referred by fm and returns reference to the object changed. Function throws cvmexception if sizes of objects or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} x");
funcs2.push_back("{x,y} 1");
funcs2.push_back("{x,y} 2");
funcs2.push_back("{x,y} y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfmatrix rfm(2,2,funcs2);
cfmatrix cfm(2,2,funcs2);
rfvector rfv2(2);
cfvector cfv2(2);
rfv2.mult(rfv1,rfm);
cfv2.mult(cfv1,cfm);
std::cout << rfm << std::endl;
std::cout << rfv2 << std::endl;
std::cout << cfm << std::endl;
std::cout << cfv2 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x {x,y} 2
{x,y} 1 {x,y} y
{x,y} x^2+x+y {x,y} x*2+(x+y)*y
{x,y} x {x,y} (2,0)
{x,y} (1,0) {x,y} y
{x,y} x^(2,0)+x+y {x,y} x*(2,0)+(x+y)*y
Parameters
[in]fvVector of functions to multiply.
[in]fmMatrix of functions to multiply by.
Returns
Reference to changed calling vector.

Definition at line 8978 of file cfun.h.

template<typename T>
basic_fvector& basic_fvector< T >::mult ( const basic_fmatrix< T > &  fm,
const basic_fvector< T > &  fv 
) throw (cvmexception)
inline

Matrix by vector product

Sets basic_fvector object to be equal to product of matrix of functions referred by fm and vector of functions referred by fv and returns reference to the object changed. FUnction throws cvmexception if sizes of objects or lists of variables don't match.

Example:
using namespace cvm;
try{
string_array funcs1, funcs2;
funcs1.push_back("{x,y} x");
funcs1.push_back("{x,y} x + y");
funcs2.push_back("{x,y} x");
funcs2.push_back("{x,y} 1");
funcs2.push_back("{x,y} 2");
funcs2.push_back("{x,y} y");
rfvector rfv1(funcs1);
cfvector cfv1(funcs1);
rfmatrix rfm(2,2,funcs2);
cfmatrix cfm(2,2,funcs2);
rfvector rfv2(2);
cfvector cfv2(2);
rfv2.mult(rfm,rfv1);
cfv2.mult(cfm,cfv1);
std::cout << rfm << std::endl;
std::cout << rfv2 << std::endl;
std::cout << cfm << std::endl;
std::cout << cfv2 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} x {x,y} 2
{x,y} 1 {x,y} y
{x,y} x^2+2*(x+y) {x,y} x+y*(x+y)
{x,y} x {x,y} (2,0)
{x,y} (1,0) {x,y} y
{x,y} x^(2,0)+(2,0)*(x+y) {x,y} x+y*(x+y)
Parameters
[in]fmMatrix of functions to multiply.
[in]fvVector of functions to multiply by.
Returns
Reference to changed calling vector.

Definition at line 9036 of file cfun.h.

template<typename T>
basic_fmatrix<T> basic_fvector< T >::jacobian ( size_t  nfrom = 0,
size_t  vars = 0 
) const
inline

Jacobi matrix.

Creates basic_fmatrix object as Jacobi matrix of calling vector of functions. First variable to compute partial derivatives is set by nfrom index (0-based, 0 by default), the number of variables to use is set by vars argument (0 for all, default). Number of rows of the Jacobi matrix built is equal to vector's size, number of columns is the number of variables used to compute it. Function throws cvmexception if the numbers are out of boundaries.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv.jacobian() << std::endl;
std::cout << cfv.jacobian() << std::endl;
std::cout << rfv.jacobian(0,1) << std::endl;
std::cout << cfv.jacobian(0,1) << std::endl;
std::cout << rfv.jacobian(1) << std::endl;
std::cout << cfv.jacobian(1) << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} 1 {x,y} 1
{x,y} y {x,y} x
{x,y} y*x^(y-1) {x,y} x^y*log(x)
{x,y} (1,0) {x,y} (1,0)
{x,y} y {x,y} x
{x,y} y*x^(y-(1,-0)) {x,y} x^y*log(x)
{x,y} 1
{x,y} y
{x,y} y*x^(y-1)
{x,y} (1,0)
{x,y} y
{x,y} y*x^(y-(1,-0))
{x,y} 1
{x,y} x
{x,y} x^y*log(x)
{x,y} (1,0)
{x,y} x
{x,y} x^y*log(x)
Parameters
[in]nfrom0-based index (0 by default) of variable to start with.
[in]varsNumber of variables to compute Jacobian metrix for (0 for all, default).
Returns
basic_fmatrix Jacobi matrix object.

Definition at line 9103 of file cfun.h.

template<typename T>
void basic_fvector< T >::jacobian ( basic_fmatrix< T > &  fmj,
size_t  nfrom = 0,
size_t  vars = 0 
) const
inline

Jacobi matrix.

Computes Jacobi matrix of calling vector of functions and sets fmj basic_fmatrix object to it. First variable to compute partial derivatives is set by nfrom index (0-based, 0 by default), the number of variables to use is set by vars argument (0 for all, default). Number of rows of the Jacobi matrix built must be equal to vector's size, number of columns is the number of variables used to compute it. Function throws cvmexception otherwise.

Example:
using namespace cvm;
try{
string_array funcs;
funcs.push_back("{x,y} x+y+1");
funcs.push_back("{x,y} x*y");
funcs.push_back("{x,y} x^y");
rfvector rfv(funcs);
cfvector cfv(funcs);
rfmatrix rm32(3,2), rm31(3,1);
cfmatrix cm32(3,2), cm31(3,1);
rfv.jacobian(rm32);
std::cout << rm32 << std::endl;
cfv.jacobian(cm32);
std::cout << cm32 << std::endl;
rfv.jacobian(rm31,0,1);
std::cout << rm31 << std::endl;
cfv.jacobian(cm31,0,1);
std::cout << cm31 << std::endl;
rfv.jacobian(rm31,1);
std::cout << rm31 << std::endl;
cfv.jacobian(cm31,1);
std::cout << cm31 << std::endl;
}
catch (std::exception& e) {
std::cout << "Exception " << e.what () << std::endl;
}
prints
{x,y} 1 {x,y} 1
{x,y} y {x,y} x
{x,y} y*x^(y-1) {x,y} x^y*log(x)
{x,y} (1,0) {x,y} (1,0)
{x,y} y {x,y} x
{x,y} y*x^(y-(1,-0)) {x,y} x^y*log(x)
{x,y} 1
{x,y} y
{x,y} y*x^(y-1)
{x,y} (1,0)
{x,y} y
{x,y} y*x^(y-(1,-0))
{x,y} 1
{x,y} x
{x,y} x^y*log(x)
{x,y} (1,0)
{x,y} x
{x,y} x^y*log(x)
Parameters
[out]fmjJacobi matrix to compute.
[in]nfrom0-based index (0 by default) of variable to start with.
[in]varsNumber of variables to compute Jacobian metrix for (0 for all, default).

Definition at line 9190 of file cfun.h.

Friends And Related Function Documentation

template<typename T>
friend class basic_fmatrix< T >
friend

Definition at line 7941 of file cfun.h.

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const basic_fvector< T > &  fv 
)
friend

Output operator.

Prints vector of functions referred by fv to output stream referred by os using Wolfram's Mathemaca syntax {var1[,var2,...]} expr for each element.

Example:
funcs.push_back("{x,y} x");
funcs.push_back("{x,y} x + y");
funcs.push_back("{x,y} x*y + 1");
rfvector rfv(funcs);
cfvector cfv(funcs);
std::cout << rfv;
std::cout << cfv;
prints
{x,y} x {x,y} x+y {x,y} x*y+1
{x,y} x {x,y} x+y {x,y} x*y+(1,0)
Parameters
[in]osReference to output stream.
[in]fvConst reference to vector of functions to print.
Returns
Reference to output stream.

Definition at line 9231 of file cfun.h.


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