CPP Linear Algebra ToolBox  0.1.0
vector.cpp File Reference
Include dependency graph for vector.cpp:

Functions

bool operator== (const Vector &lhs, const Vector &rhs)
 Overload of the equality operator for Vector objects. Two vectors are said to be equal if and only if they have the same dimension and they have exactly the same values. More...
 
double operator* (const Vector &lhs, const Vector &rhs)
 Dot product between vectors. More...
 
Vector operator* (const double d, const Vector &v)
 Operator of multiplication of a Vector object by a scalar. More...
 
Vector operator* (const Vector &v, const double d)
 Operator of multiplication of a Vector object by a scalar. More...
 
Vector operator+ (const Vector &lhs, const Vector &rhs)
 Addition of two vector objects. More...
 
Vector operator+ (const double d, const Vector &v)
 Operator of addition of a Vector object with a scalar. More...
 
Vector operator+ (const Vector &v, const double d)
 Operator of addition of a Vector object with a scalar. More...
 
Vector operator- (const Vector &lhs, const Vector &rhs)
 Substract two vector objects. More...
 
Vector operator- (const double d, const Vector &v)
 Operator of remove a scalar to a Vector. More...
 
Vector operator- (const Vector &v, const double d)
 Operator of remove a scalar to a Vector. More...
 
Vector operator/ (const Vector &v, const double d)
 Operator to divide a Vector by a scalar. More...
 
std::ostream & operator<< (std::ostream &os, const Vector &v)
 Overload output stream operator for Vector object. More...
 
Vector abs (const Vector &v)
 Elementwise absolute value of a vector. More...
 
Vector pow2 (const Vector &v)
 Elementwise square of a vector. More...
 
double prod (const Vector &v)
 Compute the product of the element of a vector. More...
 
Vector prod (const Vector &v1, const Vector &v2)
 Compute the elementwise product of two vectors. More...
 
Vector sqrt (const Vector &v)
 Elementwise square root of a vector. More...
 
double sum (const Vector &v)
 Compute the sum of the element of a vector. More...
 

Function Documentation

◆ abs()

Vector abs ( const Vector v)

Elementwise absolute value of a vector.

Parameters
va vector
Returns
Vector a vector whose components are the absolute value of the components of v

◆ operator*() [1/3]

Vector operator* ( const double  d,
const Vector v 
)

Operator of multiplication of a Vector object by a scalar.

Parameters
dDouble value to multiply v with
vVector to be multiplied
Returns
Vector whose components are v[i]*d

◆ operator*() [2/3]

double operator* ( const Vector lhs,
const Vector rhs 
)

Dot product between vectors.

Parameters
lhsLeft Hand Side
rhsRight Hand Side
Returns
double Dot product between vetcor object and v
Warning
Both vectors must be of the same dimension.

◆ operator*() [3/3]

Vector operator* ( const Vector v,
const double  d 
)

Operator of multiplication of a Vector object by a scalar.

Parameters
vVector to be multiplied
dDouble value to multiply v with
Returns
Vector whose components are v[i]*d

◆ operator+() [1/3]

Vector operator+ ( const double  d,
const Vector v 
)

Operator of addition of a Vector object with a scalar.

Parameters
dDouble value added to v
vVector to be additioned
Returns
Vector whose components are v[i] + d

◆ operator+() [2/3]

Vector operator+ ( const Vector lhs,
const Vector rhs 
)

Addition of two vector objects.

Parameters
lhsA vector of dimension \(n\),
rhsA vector of dimension \(n\)
Warning
lhs and rhs must be of the same dimension.
Returns
Vector Sum of lhs and rhs.

◆ operator+() [3/3]

Vector operator+ ( const Vector v,
const double  d 
)

Operator of addition of a Vector object with a scalar.

Parameters
vVector to be additioned
dDouble value added to v
Returns
Vector whose components are v[i] + d

◆ operator-() [1/3]

Vector operator- ( const double  d,
const Vector v 
)

Operator of remove a scalar to a Vector.

Parameters
dDouble value to remove fro v
vRight Hand Side
Returns
Vector whose components are d - v[i]

◆ operator-() [2/3]

Vector operator- ( const Vector lhs,
const Vector rhs 
)

Substract two vector objects.

Parameters
lhsA vector of dimension \(n\),
rhsA vector of dimension \(n\)
Warning
lhs and rhs must be of the same dimension.
Returns
Vector Difference of lhs and rhs.

◆ operator-() [3/3]

Vector operator- ( const Vector v,
const double  d 
)

Operator of remove a scalar to a Vector.

Parameters
vLeft Hand Side
dDouble value to remove from v
Returns
Vector whose components are v[i] - d

◆ operator/()

Vector operator/ ( const Vector v,
const double  d 
)

Operator to divide a Vector by a scalar.

Parameters
vVector v
dDouble value to divide v (must be non-zero)
Returns
Vector whose components are v[i] / d
Warning
d must me non-zero

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const Vector v 
)

Overload output stream operator for Vector object.

Parameters
osOutput stream.
vVector object.
Returns
std::ostream & updated output stream

◆ operator==()

bool operator== ( const Vector lhs,
const Vector rhs 
)

Overload of the equality operator for Vector objects. Two vectors are said to be equal if and only if they have the same dimension and they have exactly the same values.

Parameters
lhsLeft hand side
rhsRight hand side
Returns
true If all values of both vectors coincide.
false If at least of the value of the two vectors differ.

◆ pow2()

Vector pow2 ( const Vector v)

Elementwise square of a vector.

Parameters
va vector
Returns
Vector a vector whose components are the square of the components of v

◆ prod() [1/2]

double prod ( const Vector v)

Compute the product of the element of a vector.

Parameters
va vector object
Returns
double product of the components of \(v\)
Warning
If v has zero length then we return 1

◆ prod() [2/2]

Vector prod ( const Vector v1,
const Vector v2 
)

Compute the elementwise product of two vectors.

Parameters
v1a vector
v2a vector
Returns
Vector a vector whose elements are the product of the corresponding elements of v1 and v2
Warning
v1 and v2 must have the same dimension

◆ sqrt()

Vector sqrt ( const Vector v)

Elementwise square root of a vector.

Parameters
va vector
Returns
Vector a vector whose components are the square root of the components of v
Warning
the components must be non negative

◆ sum()

double sum ( const Vector v)

Compute the sum of the element of a vector.

Parameters
va vector object
Returns
double sum of the components of \(v\)
Warning
If v has zero length then we return 0