Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members

MVector.cpp File Reference

#include "MVector.h"

Include dependency graph for MVector.cpp:

Go to the source code of this file.

Functions

bool operator== (const MVector &mv1, const MVector &mv2)
MVector operator+ (const MVector &mv1, const MVector &mv2)
MVector operator- (const MVector &mv1, const MVector &mv2)
double operator * (const MVector &mv1, const MVector &mv2)
ostream & operator<< (ostream &os, const MVector &mv)


Function Documentation

double operator * const MVector mv1,
const MVector mv2
 

Since std::vector have no arithmetic operations, we have to do it ourselves.

Definition at line 74 of file MVector.cpp.

References MVector::_components, and MVector::_ncomps.

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 }

MVector operator+ const MVector mv1,
const MVector mv2
 

Since std::vector have no arithmetic operations, we have to do it ourselves.

Definition at line 46 of file MVector.cpp.

References MVector::_components, and MVector::_ncomps.

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 }

MVector operator- const MVector mv1,
const MVector mv2
 

Since std::vector have no arithmetic operations, we have to do it ourselves.

Definition at line 60 of file MVector.cpp.

References MVector::_components, and MVector::_ncomps.

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 }

ostream& operator<< ostream &  os,
const MVector mv
 

Enclose the list of component values between square brackets.

Definition at line 100 of file MVector.cpp.

References MVector::_components, and MVector::_ncomps.

00101 {
00102     os << "[ ";
00103     for (int i = 0; i < mv._ncomps; ++i)
00104         os << mv._components[i] << ' ';
00105     os << ']';
00106     return os;
00107 }

bool operator== const MVector mv1,
const MVector mv2
 

To check for equality, simply use operator== for std::vector.

Definition at line 37 of file MVector.cpp.

References MVector::_components, and MVector::_ncomps.

00038 {
00039     if (mv1._ncomps != mv2._ncomps) return false;
00040     return mv1._components == mv2._components;
00041 }


Generated on Mon Dec 12 18:25:44 2005 for Vectors_and_Matrices by  doxygen 1.4.3