#include <MVector.h>
Public Member Functions | |
Constructors, destructor, and conversions | |
| |
MVector (int n=0, double x=0.0) | |
Constructor (also usable as default constructor). | |
Assignments | |
| |
MVector & | operator+= (const MVector &mv) |
MVector & | operator-= (const MVector &mv) |
Accessors | |
int | ncomps () const |
Number of elements. | |
int | size () const |
Number of elements. | |
double | norm () const |
Compute the Euclidian norm of the vector. | |
Subscript | |
double & | operator[] (int i) |
Subscript for non-constant vectors. | |
double | operator[] (int i) const |
Subscript for constant vectors. | |
Private Attributes | |
int | _ncomps |
number of elements (redundant yet convenient) | |
vector< double > | _components |
the std::vector containing the elements | |
Friends | |
ostream & | operator<< (ostream &os, const MVector &mv) |
IO operation: just display the contents. | |
Arithmetic operations | |
MVector | operator+ (const MVector &mv1, const MVector &mv2) |
Addition. | |
MVector | operator- (const MVector &mv1, const MVector &mv2) |
Subtraction. | |
double | operator * (const MVector &mv1, const MVector &mv2) |
Scalar product. | |
double | dot (const MVector &mv1, const MVector &mv2) |
Another denotation for scalar product. | |
Relational operations | |
bool | operator== (const MVector &mv1, const MVector &mv2) |
Equality. | |
bool | operator!= (const MVector &mv1, const MVector &mv2) |
Unequality. | |
Classes | |
class | Bad_Dimensions |
class | Out_Of_Bounds |
MVector is implemented using an STL vector<double>.
Definition at line 23 of file MVector.h.
|
Constructor (also usable as default constructor). No surprise here: we simply call the adequate constructor of std::vector.
Definition at line 17 of file MVector.cpp. 00018 : _ncomps(n), _components(n, x) 00019 { 00020 // Nothing else to do 00021 }
|
|
Number of elements.
Definition at line 68 of file MVector.h. References _ncomps. Referenced by size(). 00068 {return _ncomps;}
|
|
Compute the Euclidian norm of the vector. We use the scalar product of the vector by itself.
Definition at line 28 of file MVector.cpp. Referenced by main().
|
|
Definition at line 58 of file MVector.h.
|
|
Definition at line 59 of file MVector.h.
|
|
Subscript for constant vectors.
Definition at line 91 of file MVector.cpp. References _components, and _ncomps. 00092 { 00093 if (i < 0 || i >= _ncomps) throw Out_Of_Bounds(); 00094 return _components[i]; 00095 }
|
|
Subscript for non-constant vectors.
Definition at line 85 of file MVector.cpp. References _components, and _ncomps. 00086 { 00087 if (i < 0 || i >= _ncomps) throw Out_Of_Bounds(); 00088 return _components[i]; 00089 }
|
|
Number of elements.
Definition at line 70 of file MVector.h. References ncomps(). 00070 {return ncomps();}
Here is the call graph for this function: ![]() |
|
Another denotation for scalar product.
Definition at line 88 of file MVector.h.
|
|
Scalar product. Since std::vector have no arithmetic operations, we have to do it ourselves. Definition at line 74 of file MVector.cpp. 00075 { 00076 if (mv1._ncomps != mv2._ncomps) throw MVector::Bad_Dimensions(); 00077 00078 int n = mv1._ncomps; 00079 double prod = 0.0; 00080 for (int i = 0; i < n; ++i) 00081 prod += mv1._components[i] * mv2._components[i]; 00082 return prod; 00083 }
|
|
Unequality.
Definition at line 102 of file MVector.h.
|
|
Addition. Since std::vector have no arithmetic operations, we have to do it ourselves. Definition at line 46 of file MVector.cpp. 00047 { 00048 if (mv1._ncomps != mv2._ncomps) throw MVector::Bad_Dimensions(); 00049 00050 int n = mv1._ncomps; 00051 MVector mv(n); 00052 for (int i = 0; i < n; ++i) 00053 mv._components[i] = mv1._components[i] + mv2._components[i]; 00054 return mv; 00055 }
|
|
Subtraction. Since std::vector have no arithmetic operations, we have to do it ourselves. Definition at line 60 of file MVector.cpp. 00061 { 00062 if (mv1._ncomps != mv2._ncomps) throw MVector::Bad_Dimensions(); 00063 00064 int n = mv1._ncomps; 00065 MVector mv(n); 00066 for (int i = 0; i < n; ++i) 00067 mv._components[i] = mv1._components[i] - mv2._components[i]; 00068 return mv; 00069 }
|
|
IO operation: just display the contents. Enclose the list of component values between square brackets. Definition at line 100 of file MVector.cpp. 00101 { 00102 os << "[ "; 00103 for (int i = 0; i < mv._ncomps; ++i) 00104 os << mv._components[i] << ' '; 00105 os << ']'; 00106 return os; 00107 }
|
|
Equality. To check for equality, simply use operator== for std::vector. Definition at line 37 of file MVector.cpp. 00038 { 00039 if (mv1._ncomps != mv2._ncomps) return false; 00040 return mv1._components == mv2._components; 00041 }
|
|
the std::vector containing the elements
Definition at line 28 of file MVector.h. Referenced by operator *(), operator+(), operator-(), operator<<(), operator==(), and operator[](). |
|
number of elements (redundant yet convenient)
Definition at line 27 of file MVector.h. Referenced by ncomps(), operator *(), operator+(), operator-(), operator<<(), operator==(), and operator[](). |