CAPD DynSys Library  5.2.0
Vectors

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.

// the following lines define new names for four dimensional vectors
// the following lines define new names for vectors of an arbitrarily length

How to create a vector

// The following line creates a four dimensional vector filled by zeros
DVector4D x;
// Vector y will be a five dimensional interval vector filled by zeros
IVector y(5);
// The following lines create objects from a given table of numbers.
// In fact, the dimension is known, but the interfaces for both types of vectors
// (dynamic table and internal array) are the same - so we must specify the dimension in both cases
double data1[] = {1.,2.,3.,4.};
double data2[] = {4.,3.,2.,1.};
DVector4D a(4,data1);
DVector4D b(4,data2);

How to create an array of vectors

// When one needs to create an array of vectors which have undefined dimensions at compilation time,
// the following solution is available. The class Vector has a static function, which creates an array of vectors
// of specified dimension. Here we create an array of six vectors, each of dimension 5.

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]; // prints on the screen i-th coordinate of a vector b
a[i] = i*i; // sets i-th coordinate of a vector 'a' to be equal to 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.
    // create an interval vector
    DInterval d1[] = {DInterval(-1.,1.), DInterval(2.,2.), DInterval(3.,3.1), DInterval(4.,4.1)};
    IVector v1(4,d1);
    std::cout << midVector(v1);
    // result : {[0,0],[2,2],[3.05,3.05],[4.05,4.05]}
  • 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

    split(v1,v2); // assume v1 is as in the previous example

    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;
    one should obtain on the screen
    leftVector(v2)= {[-1,-1],[0,0],[-0.05,-0.05],[-0.05,-0.05]}
    rightVector(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;

    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>
    IVector intersection(const IVector& x, const IVector& y);
    returns an intersection of two interval vectors or throws an exception if their intersection is empty.
capd::vectalg::rightVector
IVector rightVector(const IVector &u)
Definition: Vector_Interval.hpp:36
capd::vectalg::Vector::makeArray
static Vector * makeArray(size_type N, size_type _dim)
Definition: Vector.hpp:63
capd::vectalg::Vector
Definition: ColumnVector.h:177
capd::intervals::diam
Interval< T_Bound, T_Rnd > diam(const Interval< T_Bound, T_Rnd > &)
upper bound for a diameter of an interval
Definition: Interval_Fun.hpp:132
capd::vectalg::leftVector
IVector leftVector(const IVector &u)
Definition: Vector_Interval.hpp:29
capd::pdes::midVector
GeometricBound midVector(const GeometricBound &x)
Definition: GeometricBound.h:273
capd::intervals::split
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
capd::intervals::intersection
bool intersection(Interval< T_Bound, T_Rnd > A_iv1, Interval< T_Bound, T_Rnd > A_iv2, Interval< T_Bound, T_Rnd > &A_rIntersection)
Intersection of two intervals.
Definition: Interval_Fun.hpp:163
capd::intervals::Interval
Definition of template class Interval.
Definition: Interval.h:41