Heidelberg Educational Numerics Library Version 0.27 (from 15 March 2021)
Public Types | Public Member Functions | Related Symbols | List of all members
hdnum::Vector< REAL > Class Template Reference

Class with mathematical vector operations. More...

#include <vector.hh>

Inheritance diagram for hdnum::Vector< REAL >:

Public Types

typedef std::size_t size_type
 Type used for array indices.
 

Public Member Functions

 Vector ()
 default constructor, also inherited from the STL vector default constructor
 
 Vector (const size_t size, const REAL defaultvalue_=0)
 another constructor, with arguments, setting the default value for all entries of the vector of given size
 
 Vector (const std::initializer_list< REAL > &v)
 constructor from initializer list
 
Vectoroperator= (const REAL value)
 Assign all values of the Vector from one scalar value: x = value.
 
Vector sub (size_type i, size_type m)
 Subvector extraction.
 
Vectoroperator*= (const REAL value)
 Multiplication by a scalar value (x *= value)
 
Vectoroperator/= (const REAL value)
 Division by a scalar value (x /= value)
 
Vectoroperator+= (const Vector &y)
 Add another vector (x += y)
 
Vectoroperator-= (const Vector &y)
 Subtract another vector (x -= y)
 
Vectorupdate (const REAL alpha, const Vector &y)
 Update vector by addition of a scaled vector (x += a y )
 
REAL operator* (Vector &x) const
 Inner product with another vector.
 
Vector operator+ (Vector &x) const
 Adding two vectors x+y.
 
Vector operator- (Vector &x) const
 vector subtraction x-y
 
REAL two_norm_2 () const
 Square of the Euclidean norm.
 
REAL two_norm () const
 Euclidean norm of a vector.
 
bool scientific () const
 pretty-print output property: true = scientific, false = fixed point representation
 
void scientific (bool b) const
 scientific(true) is the default, scientific(false) switches to the fixed point representation
 
std::size_t iwidth () const
 get index field width for pretty-printing
 
std::size_t width () const
 get data field width for pretty-printing
 
std::size_t precision () const
 get data precision for pretty-printing
 
void iwidth (std::size_t i) const
 set index field width for pretty-printing
 
void width (std::size_t i) const
 set data field width for pretty-printing
 
void precision (std::size_t i) const
 set data precision for pretty-printing
 

Related Symbols

(Note that these are not member symbols.)

template<typename REAL >
std::ostream & operator<< (std::ostream &os, const Vector< REAL > &x)
 Output operator for Vector.
 
template<typename REAL >
void gnuplot (const std::string &fname, const Vector< REAL > x)
 Output contents of a Vector x to a text file named fname.
 
template<typename REAL >
void readVectorFromFile (const std::string &filename, Vector< REAL > &vector)
 Read vector from a text file.
 
template<class REAL >
void fill (Vector< REAL > &x, const REAL &t, const REAL &dt)
 Fill vector, with entries starting at t, consecutively shifted by dt.
 
template<class REAL >
void unitvector (Vector< REAL > &x, std::size_t j)
 Defines j-th unitvector (j=0,...,n-1) where n = length of the vector.
 

Detailed Description

template<typename REAL>
class hdnum::Vector< REAL >

Class with mathematical vector operations.

Member Function Documentation

◆ operator*()

template<typename REAL >
REAL hdnum::Vector< REAL >::operator* ( Vector< REAL > & x) const
inline

Inner product with another vector.

Example:

x.scientific(false); // set fixed point display mode
x[0] = 12.0;
x[1] = 3.0;
std::cout << "x=" << x << std::endl;
y[0] = 4.0;
y[1] = -1.0;
std::cout << "y=" << y << std::endl;
double s = x*y;
std::cout << "s = x*y = " << s << std::endl;
Class with mathematical matrix operations.
Definition densematrix.hh:33

Output:

x=
[ 0]     12.0000000
[ 1]      3.0000000

y=
[ 0]      4.0000000
[ 1]     -1.0000000

s = x*y = 45.0000000

◆ operator+()

template<typename REAL >
Vector hdnum::Vector< REAL >::operator+ ( Vector< REAL > & x) const
inline

Adding two vectors x+y.

Example:

x.scientific(false); // set fixed point display mode
x[0] = 12.0;
x[1] = 3.0;
std::cout << "x=" << x << std::endl;
y[0] = 4.0;
y[1] = -1.0;
std::cout << "y=" << y << std::endl;
std::cout << "x+y = " << x+y << std::endl;

Output:

x=
[ 0]     12.0000000
[ 1]      3.0000000

y=
[ 0]      4.0000000
[ 1]     -1.0000000

x+y =
[ 0]     16.0000000
[ 1]      2.0000000

◆ operator-()

template<typename REAL >
Vector hdnum::Vector< REAL >::operator- ( Vector< REAL > & x) const
inline

vector subtraction x-y

Example:

x.scientific(false); // set fixed point display mode
x[0] = 12.0;
x[1] = 3.0;
std::cout << "x=" << x << std::endl;
y[0] = 4.0;
y[1] = -1.0;
std::cout << "y=" << y << std::endl;
std::cout << "x-y = " << x-y << std::endl;

Output:

x=
[ 0]     12.0000000
[ 1]      3.0000000

y=
[ 0]      4.0000000
[ 1]     -1.0000000

x-y =
[ 0]      8.0000000
[ 1]      4.0000000

◆ operator=()

template<typename REAL >
Vector & hdnum::Vector< REAL >::operator= ( const REAL value)
inline

Assign all values of the Vector from one scalar value: x = value.

Parameters
[in]valueconstant value which should be assigned

Example:

x = 1.23;
std::cout << "x=" << x << std::endl;

Output:

x=
[ 0]  1.2340000e+00
[ 1]  1.2340000e+00
[ 2]  1.2340000e+00
[ 3]  1.2340000e+00

◆ scientific()

template<typename REAL >
void hdnum::Vector< REAL >::scientific ( bool b) const
inline

scientific(true) is the default, scientific(false) switches to the fixed point representation

Example:

x[0] = 2.0;
x[1] = 2.0;
x[2] = 1.0;
std::cout << "x=" << x << std::endl;
x.scientific(false); // set fixed point display mode
std::cout << "x=" << x << std::endl;

Output:

x=
[ 0]  2.0000000e+00
[ 1]  2.0000000e+00
[ 2]  1.0000000e+00

x=
[ 0]      2.0000000
[ 1]      2.0000000
[ 2]      1.0000000

◆ sub()

template<typename REAL >
Vector hdnum::Vector< REAL >::sub ( size_type i,
size_type m )
inline

Subvector extraction.

Returns a new vector that is a subset of the components of the given vector.

Parameters
[in]ifirst index of the new vector
[in]msize of the new vector, i.e. it has components [i,i+m-1]

◆ two_norm()

template<typename REAL >
REAL hdnum::Vector< REAL >::two_norm ( ) const
inline

Euclidean norm of a vector.

Example:

x.scientific(false); // set fixed point display mode
x[0] = 2.0;
x[1] = 2.0;
x[2] = 1.0;
std::cout << "x=" << x << std::endl;
std::cout << "euclidean norm of x = " << x.two_norm() << std::endl;

Output:

x=
[ 0]      2.0000000
[ 1]      2.0000000
[ 2]      1.0000000

euclidean norm of x = 3.0000000

Friends And Related Symbol Documentation

◆ fill()

template<class REAL >
void fill ( Vector< REAL > & x,
const REAL & t,
const REAL & dt )
related

Fill vector, with entries starting at t, consecutively shifted by dt.

Example:

fill(x,2.01,0.1);
x.scientific(false); // set fixed point display mode
std::cout << "x=" << x << std::endl;
void fill(Vector< REAL > &x, const REAL &t, const REAL &dt)
Fill vector, with entries starting at t, consecutively shifted by dt.
Definition vector.hh:769

Output:

x=
[ 0]      2.0100000
[ 1]      2.1100000
[ 2]      2.2100000
[ 3]      2.3100000
[ 4]      2.4100000

◆ gnuplot()

template<typename REAL >
void gnuplot ( const std::string & fname,
const Vector< REAL > x )
related

Output contents of a Vector x to a text file named fname.

Example:

x.scientific(false); // set fixed point display mode
gnuplot("test.dat",x);
void unitvector(Vector< REAL > &x, std::size_t j)
Defines j-th unitvector (j=0,...,n-1) where n = length of the vector.
Definition vector.hh:803
void gnuplot(const std::string &fname, const Vector< REAL > x)
Output contents of a Vector x to a text file named fname.
Definition vector.hh:552

Output:

Contents of 'test.dat':
0      0.0000000
1      0.0000000
2      0.0000000
3      1.0000000
4      0.0000000

◆ operator<<()

template<typename REAL >
std::ostream & operator<< ( std::ostream & os,
const Vector< REAL > & x )
related

Output operator for Vector.

Example:

x[0] = 2.0;
x[1] = 2.0;
x[2] = 1.0;
std::cout << "x=" << x << std::endl;

Output:

x=
[ 0]  2.0000000e+00
[ 1]  2.0000000e+00
[ 2]  1.0000000e+00

◆ readVectorFromFile()

template<typename REAL >
void readVectorFromFile ( const std::string & filename,
Vector< REAL > & vector )
related

Read vector from a text file.

Parameters
[in]filenamename of the text file
[in,out]vectorreference to a Vector

Example:

readVectorFromFile("x.dat", x );
std::cout << "x=" << x << std::endl;
void readVectorFromFile(const std::string &filename, Vector< REAL > &vector)
Read vector from a text file.
Definition vector.hh:697

Output:

Contents of "x.dat":
1.0
2.0
3.0

would give:
x=
[ 0]  1.0000000e+00
[ 1]  2.0000000e+00
[ 2]  3.0000000e+00

◆ unitvector()

template<class REAL >
void unitvector ( Vector< REAL > & x,
std::size_t j )
related

Defines j-th unitvector (j=0,...,n-1) where n = length of the vector.

Example:

x.scientific(false); // set fixed point display mode
std::cout << "x=" << x << std::endl;

Output:

x=
[ 0]      0.0000000
[ 1]      0.0000000
[ 2]      0.0000000
[ 3]      1.0000000
[ 4]      0.0000000

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