Vectors

Header file vector.h

General vector class

Name
Vector
Inheritance
array of doubles: Array<double>

Constituents

(As for Array<double>)

Methods

(Extending Array<double>)
Creation
Input and output
(Array class inherits from Classio and provides Read and Write operations which allow the << and >> operators to be used, in which case the number of elements is read from and written to the I/O stream. Array also provides Read_elements and Write_elements methods to read and write the element list only, without the number of elements.) e.g.
Vector x; cin >> x; cout << x << endl; x.Write_elements(cout);
Assignment
=

e.g. Vector x,y; cin >> x; y = x;

Extract a sub-vector
   Vector subvector(
      const int i0, // first index of subvector
      const int i1  // last index of subvector
   ) const

e.g. Vector y = x.subvector(0,4);

Inner product
The following methods all return a.b, where a and b are vectors with the same number of elements.

e.g.

   Vector x,y; cin >> x >> y;
   double a = inner_product(x,y), b = dot(x,y), c = x * y; // a = b = c
Norm
(Sum of squares of elements.) friend double norm(const Vector& a)

e.g. vector a; cin >> a; double anorm = norm(a);

Length
friend double length(const Vector& a)

e.g. Vector a; cin >> a; double alen = length(a);

Normalise
(Scale to unit length.) friend void normalise(Vector& a)

e.g. vector a; cin >> a; normalise(a); cout << a;

Arithmetic operations
These methods allow conventional-looking equations to be written with vector quantities.

General vector class (fixed dimension)

Name
Vector_fixed_dimension
Inheritance
vector
A Vector_fixed_dimension is exactly the same as a vector, except that the Read and Write methods are redefined to omit the number of elements. (This means that the number of elements must be set before a Vector_fixed_dimension is read.)

This class is the base for vectors of a specific dimension.

4D vector class

Name
Vector4d
Inheritance
Vector_fixed_dimension

3D vector class

Name
Vector3d
Inheritance
Vector_fixed_dimension

Methods

Cross product
Calculate the vector (cross) product of two vectors.
Vector triple product
Calculates the volume a.(b^c).
   friend double vector_triple_product(const Vector3d& a, const Vector3d& b,
      const Vector3d& c)
Rotation
Axis vectors must be of unit length.

2D vector class

Name
Vector2d
Inheritance
Vector_fixed_dimension

Methods

Cross product
Calculates the real value a^b.
   friend double operator^(const Vector2d& a, const Vector2d& b)
Rotation

General real vector class

This is a prototype class for research into structures of arbitrary type.
Name
Real_vector
Inheritance
Arithmetic_matrix<double>