Carmen Code
 All Classes Files Functions Variables Macros Pages
Functions
Vector.cpp File Reference

Creates vector structure. More...

#include <math.h>
#include <iostream>
#include "PreProcessor.h"
#include "Vector.h"
Include dependency graph for Vector.cpp:

Functions

Vector operator* (const real a, const Vector &V)
 Returns the product of the current vector and a real a. More...
 
int dim (const Vector &V)
 Returns the dimension of the vector. Similar to int Vector::dimension(). More...
 
Vector abs (const Vector &V)
 Returns the absolute value term by term of the vector. More...
 
real N1 (const Vector &V)
 Returns the L1-norm of the vector. More...
 
real N2 (const Vector &V)
 Returns the L2-norm of the vector. More...
 
real NMax (const Vector &V)
 Returns the Max-norm of the vector. More...
 
ostream & operator<< (ostream &out, const Vector &V)
 Writes the components of the vector V on screen. More...
 

Detailed Description

Creates vector structure.

Function Documentation

Vector abs ( const Vector V)

Returns the absolute value term by term of the vector.

Parameters
VVector
Returns
Vector
1485 {
1486  int n;
1487  real a;
1488  Vector result( dim(V) );
1489 
1490  for (n = 1; n <= dim(V); n++)
1491  {
1492  a = V.value(n);
1493  if (a < 0.)
1494  result.setValue(n, -a);
1495  else
1496  result.setValue(n, a);
1497  }
1498  return result;
1499 }
Standard class for every vector in Carmen.
Definition: Vector.h:29
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
#define real
Definition: PreProcessor.h:31
int dim ( const Vector V)

Returns the dimension of the vector. Similar to int Vector::dimension().

Parameters
VVector
Returns
int
1474 {
1475  return V.dimension();
1476 }
int dimension() const
Returns the dimension of the vector.
Definition: Vector.h:535

Here is the caller graph for this function:

real N1 ( const Vector V)

Returns the L1-norm of the vector.

Parameters
VVector
Returns
real
1508 {
1509  int n;
1510  real result;
1511 
1512  result = 0.;
1513  for (n = 1; n <= dim(V); n++)
1514  result += fabs(V.value(n));
1515 
1516  return result;
1517 }
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
#define real
Definition: PreProcessor.h:31
real N2 ( const Vector V)

Returns the L2-norm of the vector.

Parameters
VVector
Returns
real
1526 {
1527  int n;
1528  real result;
1529 
1530  result = 0.;
1531  for (n = 1; n <= dim(V); n++)
1532  result += V.value(n)*V.value(n);
1533 
1534  return sqrt(result);
1535 }
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

real NMax ( const Vector V)

Returns the Max-norm of the vector.

Parameters
VVector
Returns
real
1544 {
1545  int n;
1546  real result;
1547 
1548  result = 0.;
1549  for (n = 1; n <= dim(V); n++)
1550  if (result < fabs(V.value(n))) result = fabs(V.value(n));
1551 
1552  return result;
1553 }
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565
#define real
Definition: PreProcessor.h:31

Here is the caller graph for this function:

Vector operator* ( const real  a,
const Vector V 
)

Returns the product of the current vector and a real a.

Example :

#include "Vector.h"

Vector V(1.,0.,0.);
Vector W;
real x = 2.;
...
W = x*V;

The operation W = V*x can also be done. See Vector Vector::operator*(const real a) const.

Parameters
aReal value
VVector
Returns
Vector

1463 {
1464  return V*a;
1465 }
ostream& operator<< ( ostream &  out,
const Vector V 
)

Writes the components of the vector V on screen.

Parameters
out
VVector
Returns
ostream&
1563 {
1564  int n;
1565 
1566  for (n = 1; n <= dim(V); n++)
1567  {
1568  out<<n<<": "<<V.value(n)<<endl;
1569  }
1570  return out;
1571 }
int dim(const Vector &V)
Returns the dimension of the vector. Similar to int Vector::dimension().
Definition: Vector.cpp:1473
real value(const int n) const
Returns the value of the component n.
Definition: Vector.h:565