Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef APFDYNAMICVECTOR_H
00009 #define APFDYNAMICVECTOR_H
00010
00014 #include "apfDynamicArray.h"
00015 #include "apfVector.h"
00016 #include <math.h>
00017 #include <iostream>
00018
00019 namespace apf {
00020
00021 class DynamicVector;
00022
00033 class DynamicVector : public DynamicArray<double>
00034 {
00035 public:
00037 DynamicVector() {}
00039 DynamicVector(std::size_t n):DynamicArray<double>(n) {}
00044 double operator()(std::size_t i) const
00045 {
00046 return (*this)[i];
00047 }
00049 double& operator()(std::size_t i)
00050 {
00051 return (*this)[i];
00052 }
00054 DynamicVector& operator+=(DynamicVector const& b)
00055 {
00056 for (std::size_t i=0; i < size(); ++i)
00057 (*this)[i] += b[i];
00058 return *this;
00059 }
00061 DynamicVector& operator-=(DynamicVector const& b)
00062 {
00063 for (std::size_t i=0; i < size(); ++i)
00064 (*this)[i] -= b[i];
00065 return *this;
00066 }
00068 DynamicVector& operator*=(double s)
00069 {
00070 for (std::size_t i=0; i < size(); ++i)
00071 (*this)[i] *= s;
00072 return *this;
00073 }
00075 DynamicVector& operator/=(double s)
00076 {
00077 for (std::size_t i=0; i < size(); ++i)
00078 (*this)[i] /= s;
00079 return *this;
00080 }
00082 double operator*(DynamicVector const& b) const
00083 {
00084 double r=0;
00085 for (std::size_t i=0; i < size(); ++i)
00086 r += (*this)[i] * b[i];
00087 return r;
00088 }
00090 double getLength() {return sqrt((*this)*(*this));}
00092 void zero()
00093 {
00094 for (std::size_t i=0; i < size(); ++i)
00095 (*this)[i] = 0;
00096 }
00097 };
00098
00100 template <std::size_t N>
00101 inline DynamicVector fromVector(Vector<N> other)
00102 {
00103 DynamicVector result(N);
00104 for(std::size_t ii = 0; ii < N; ii++)
00105 result[ii] = other[ii];
00106 return result;
00107 }
00108
00109 }
00110
00111 std::ostream& operator<<(std::ostream& s, apf::DynamicVector const& x);
00112
00113 #endif