Class with mathematical vector operations. More...
#include <vector.hh>
Public Types | |
typedef std::size_t | size_type |
Type used for array indices. | |
Public Member Functions | |
Vector (const size_t size, const REAL defaultvalue_=0) | |
Vector & | operator= (const REAL &value) |
Assign all values of the Vector from one scalar value: x = value. | |
Vector & | operator= (const Vector &y) |
Assigning a vector from a given vector: x = y. | |
Vector & | operator*= (const REAL &value) |
Vector & | operator/= (const REAL &value) |
Vector & | operator+= (const Vector &y) |
Vector & | operator-= (const Vector &y) |
Vector & | update (const REAL alpha, const Vector &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 | width () const |
void | width (std::size_t i) const |
std::size_t | iwidth () const |
void | iwidth (std::size_t i) const |
std::size_t | precision () const |
void | precision (std::size_t i) const |
Related Functions | |
(Note that these are not member functions.) | |
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. |
Class with mathematical vector operations.
REAL hdnum::Vector< REAL >::operator* | ( | Vector< REAL > & | x | ) | const [inline] |
Inner product with another vector.
Example:
hdnum::Vector<double> x(2); x.scientific(false); // set fixed point display mode x[0] = 12.0; x[1] = 3.0; std::cout << "x=" << x << std::endl; hdnum::Vector<double> y(2); 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;
Output:
x= [ 0] 12.0000000 [ 1] 3.0000000 y= [ 0] 4.0000000 [ 1] -1.0000000 s = x*y = 45.0000000
Vector hdnum::Vector< REAL >::operator+ | ( | Vector< REAL > & | x | ) | const [inline] |
Adding two vectors x+y.
Example:
hdnum::Vector<double> x(2); x.scientific(false); // set fixed point display mode x[0] = 12.0; x[1] = 3.0; std::cout << "x=" << x << std::endl; hdnum::Vector<double> y(2); 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
Vector hdnum::Vector< REAL >::operator- | ( | Vector< REAL > & | x | ) | const [inline] |
vector subtraction x-y
Example:
hdnum::Vector<double> x(2); x.scientific(false); // set fixed point display mode x[0] = 12.0; x[1] = 3.0; std::cout << "x=" << x << std::endl; hdnum::Vector<double> y(2); 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
Vector& hdnum::Vector< REAL >::operator= | ( | const Vector< REAL > & | y | ) | [inline] |
Assigning a vector from a given vector: x = y.
Example:
hdnum::Vector<double> x(4); hdnum::Vector<double> y(4); x[0] = 1.23; x[1] = 2.31; x[2] = 4.54; x[3] = 9.98; std::cout << "x=" << x << std::endl; y = x; std::cout << "y=" << y << std::endl;
Output:
x= [ 0] 1.2300000e+00 [ 1] 2.3100000e+00 [ 2] 4.5400000e+00 [ 3] 9.9800000e+00 y= [ 0] 1.2300000e+00 [ 1] 2.3100000e+00 [ 2] 4.5400000e+00 [ 3] 9.9800000e+00
Vector& hdnum::Vector< REAL >::operator= | ( | const REAL & | value | ) | [inline] |
Assign all values of the Vector from one scalar value: x = value.
Example:
hdnum::Vector<double> x(4); 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
void hdnum::Vector< REAL >::scientific | ( | bool | b | ) | const [inline] |
scientific(true) is the default, scientific(false) switches to the fixed point representation
Example:
hdnum::Vector<double> x(3); 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
REAL hdnum::Vector< REAL >::two_norm | ( | ) | const [inline] |
Euclidean norm of a vector.
Example:
hdnum::Vector<double> x(3); 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
void fill | ( | Vector< REAL > & | x, | |
const REAL & | t, | |||
const REAL & | dt | |||
) | [related] |
Fill vector, with entries starting at t, consecutively shifted by dt.
Example:
hdnum::Vector<double> x(5); fill(x,2.01,0.1); x.scientific(false); // set fixed point display mode std::cout << "x=" << x << std::endl;
Output:
x= [ 0] 2.0100000 [ 1] 2.1100000 [ 2] 2.2100000 [ 3] 2.3100000 [ 4] 2.4100000
void gnuplot | ( | const std::string & | fname, | |
const Vector< REAL > | x | |||
) | [related] |
Output contents of a Vector x to a text file named fname.
Example:
hdnum::Vector<double> x(5); unitvector(x,3); x.scientific(false); // set fixed point display mode gnuplot("test.dat",x);
Output:
Contents of 'test.dat': 0 0.0000000 1 0.0000000 2 0.0000000 3 1.0000000 4 0.0000000
std::ostream & operator<< | ( | std::ostream & | os, | |
const Vector< REAL > & | x | |||
) | [related] |
Output operator for Vector.
Example:
hdnum::Vector<double> x(3); 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
void readVectorFromFile | ( | const std::string & | filename, | |
Vector< REAL > & | vector | |||
) | [related] |
Read vector from a text file.
[in] | filename | name of the text file |
[in,out] | x | reference to a Vector |
Example:
hdnum::Vector<number> x; readVectorFromFile("x.dat", x ); std::cout << "x=" << x << std::endl;
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
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:
hdnum::Vector<double> x(5); unitvector(x,3); 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