This file provides a short description on how to use class Vector from CAPD package - for more details see header file "capd/vectalg/Vector.h".
Content of this file:
Template parameters
The template class Vector is defined in the namespace capd::vectalg and it has two parameters - type of elements stored in a vector and capacity.
If capacity is larger than zero, vector is represented as an array of given length inside the object.
If capacity is set to zero, the capacity of a vector must be set when the object is created.
capd::vectalg::Vector< DInterval, 4 > IVector4D
Definition: vectorExample.cpp:19
capd::vectalg::Vector< double, 4 > DVector4D
Definition: vectorExample.cpp:18
capd::vectalg::Vector< double, 0 > DVector
Definition: vectorExample.cpp:22
capd::vectalg::Vector< DInterval, 0 > IVector
Definition: vectorExample.cpp:23
How to create a vector
double data1[] = {1.,2.,3.,4.};
double data2[] = {4.,3.,2.,1.};
How to create an array of vectors
static Vector * makeArray(size_type N, size_type _dim)
Definition: Vector.hpp:63
Indexing
One can change or access a coefficient in a vector by using operator[] or iterators. The following operations are available for vectors a,b
std::cout << b[i];
a[i] = i*i;
The index 'i' should be between 0 and the dimension of a vector minus 1, which can be easily obtained by a member function dimension as in the example below
for(int i=0; i<a.dimension(); ++i){
std::cout << "a[" << i << "]=" << a[i] << std::endl;
a[i] = i*i;
std::cout << "New value of a[" << i << "]=" << a[i] << std::endl;
}
Iterators
The other way to access a coefficient in a vector is to use iterators instead of indexing. Class Vector provides type definitions for iterators and constant iterators.
Constant iterators for constant objects are defined in the similar way
Basic operations on vectors
The following standard operations on vectors are available
sum: a+b
subtraction: a-b
euclidean scalar product: a*b
multiplication by scalar: 2*a, a*2
unary operator: -a
equality: a==b, a!=b
Moreover, the standard operations like +=, -= etc. are available when possible.
Norms and normalization
The euclidean norm of a vector can be computed be using member function euclNorm
The vector can be normalized with respect to the euclidean norm by calling member function normalize
Operations for interval vectors only
Many operations are suitable for interval vectors only. The most important are
-
taking a center of an interval vector. Function midVector returns an interval vector in which each coefficient is the center of the corresponding coefficient (an interval) in argument.
Definition of template class Interval.
Definition: Interval.h:83
capd::intervals::Interval< double, capd::rounding::DoubleRounding > DInterval
Definition: intervalExample.cpp:17
IVector midVector(const IVector &)
-
splitting - this operation is useful in Lohner algorithm. The function split(v1,v2)
has two arguments, which are modified by this function in the following way (the actual implementation uses equivalent but optimized version): v2 = v1-midVector(v1); v1 = midVector(v1); After calling
void split(Interval< T_Bound, T_Rnd > &A_iv, Interval< T_Bound, T_Rnd > &A_rMid, T_Bound &A_diam)
On output: .
Definition: Interval_Fun.hpp:192
one should obtain
v1={[0,0],[2,2],[3.05,3.05],[4.05,4.05]}
v2={[-1,1],[0,0],[-0.05,0.05],[-0.05,0.05]}
-
taking the left and right vectors. Functions leftVector, rightVector return vector of left or right ends, respectively. After calling (with v2 as above)
std::cout <<
"\nleftVector(v2)= " <<
leftVector(v2) << std::endl;
std::cout <<
"rightVector(v2)= " <<
rightVector(v2) << std::endl;
IVector leftVector(const IVector &u)
Definition: Vector_Interval.hpp:29
IVector rightVector(const IVector &u)
Definition: Vector_Interval.hpp:36
one should obtain on the screen leftVector(v2)= {[-1,-1],[0,0],[-0.05,-0.05],[-0.05,-0.05]}
-
diameter of a vector. This operation returns a vector which contains diameters of each coefficient in the argument.
After calling (with v2 as above)
std::cout <<
"diam(v2) = " <<
diam(v2) << std::endl;
Interval diam(const Interval &ix)
Definition: Interval.h:816
one should obtain
diam(v2) = {[2,2],[0,0],[0.1,0.1],[0.1,0.1]}
-
inclusions. There are two functions for verifying inclusions of vectors. Function
subset(v1,v2)
verifies if the set represented as interval vector v1 is a subset of v2. Similar function subsetInterior(v1,v2)
verifies if v1 is a subset of the interior of v2.
-
intersections. The function
template<typename IVector>
bool intersection(const Complex< T > &a, const Complex< T > &b, Complex< T > &result)
Definition: Complex.h:225
returns an intersection of two interval vectors or throws an exception if their intersection is empty.