Vtr Class Reference

#include <yang.h>

List of all members.

Public Member Functions

 Vtr (int, double *)
 Vtr (int, double=0)
 Vtr (const Vtr &)
 ~Vtr ()
Vtroperator= (const Vtr &)
Vtroperator+= (const Vtr &)
Vtroperator-= (const Vtr &)
double & operator[] (int i) const
double maxnorm () const
double twonorm () const
int size () const

Private Attributes

int lenth
double * ets

Friends

Vtr operator+ (const Vtr &)
Vtr operator- (const Vtr &)
Vtr operator+ (const Vtr &, const Vtr &)
Vtr operator- (const Vtr &, const Vtr &)
double dot (const Vtr &, const Vtr &)
Vtr operator* (const double, const Vtr &)
Vtr operator* (const Vtr &, const double)
Vtr operator* (const Vtr &, const Vtr &)
Vtr operator* (const Vtr &, const Mtx &)
Vtr operator/ (const Vtr &, const double)
std::ostream & operator<< (std::ostream &, const Vtr &)

Detailed Description

Definition at line 14 of file yang.h.


Constructor & Destructor Documentation

Vtr::Vtr ( int  n,
double *  abd 
)

Definition at line 18 of file yang.cc.

00018                            {
00019   ets = new double [lenth =n];
00020   for (int i = 0; i < lenth; i++)  ets[i]= *(abd +i);
00021 }

Vtr::Vtr ( int  n,
double  a = 0 
)

Definition at line 23 of file yang.cc.

00023                         {
00024   ets = new double [lenth =n];
00025   for (int i = 0; i < lenth; i++)  ets[i] = a;
00026 }

Vtr::Vtr ( const Vtr v  ) 

Definition at line 28 of file yang.cc.

00028                       {
00029   ets = new double [lenth = v.lenth];
00030   for (int i = 0; i < lenth; i++)  ets[i] = v[i];
00031 }

Vtr::~Vtr (  )  [inline]

Definition at line 21 of file yang.h.

00021 { delete[] ets; }  // destructor is defined inline


Member Function Documentation

double Vtr::maxnorm (  )  const

Definition at line 100 of file yang.cc.

00100                           {
00101   double norm = std::abs(ets[0]);
00102   for (int i = 1; i < lenth; i++)
00103     if (norm < std::abs(ets[i])) norm = std::abs(ets[i]);
00104   return norm;
00105 }

Vtr & Vtr::operator+= ( const Vtr v  ) 

Definition at line 45 of file yang.cc.

00045                                   {
00046   if (lenth != v.lenth ) error("bad vector sizes");
00047   for (int i = 0; i < lenth; i++) ets[i] += v[i];
00048   return *this;
00049 }

Vtr & Vtr::operator-= ( const Vtr v  ) 

Definition at line 51 of file yang.cc.

00051                                   {
00052   if (lenth != v.lenth ) error("bad vtor sizes");
00053   for (int i = 0; i < lenth; i++) ets[i] -= v[i];
00054   return *this;
00055 }

Vtr & Vtr::operator= ( const Vtr v  ) 

Definition at line 37 of file yang.cc.

00037                                 {
00038   if (this != &v) {
00039     if (lenth != v.lenth ) error("Vtr::op=: Error: Bad vector sizes");
00040     for (int i = 0; i < lenth; i++) ets[i] = v[i];
00041   }
00042   return *this;
00043 }

double& Vtr::operator[] ( int  i  )  const [inline]

Definition at line 26 of file yang.h.

00026 { return ets[i]; } // eg v[i] = 10;

int Vtr::size (  )  const [inline]

Definition at line 29 of file yang.h.

Referenced by CoordCalcFunction::endnodeDistance(), Mtx::getcol(), Mtx::operator*(), Mtx::setcol(), and CoordCalcFunction::simplex_min().

00029 { return lenth; }                 // return length of vector

double Vtr::twonorm (  )  const

Definition at line 87 of file yang.cc.

00087                          {
00088   double norm = std::abs(ets[0]);
00089   for (int i = 1; i < lenth; i++) {
00090     double vi = std::abs(ets[i]);
00091     if (norm < 100) norm = std::sqrt(norm*norm + vi*vi);
00092     else {  // to avoid overflow for fn "sqrt" when norm is large
00093       double tm = vi/norm;
00094       norm *= std::sqrt(1.0 + tm*tm);
00095     }
00096   }
00097   return norm;
00098 }


Friends And Related Function Documentation

double dot ( const Vtr v1,
const Vtr v2 
) [friend]

Definition at line 127 of file yang.cc.

00127                                            {
00128   int sz = v1.lenth;
00129   if (sz != v2.lenth ) error("bad vtor sizes");
00130   double tm = v1[0]*v2[0];
00131   for (int i = 1; i < sz; i++) tm += v1[i]*v2[i];
00132   return tm;
00133 }

Vtr operator* ( const Vtr v,
const Mtx mat 
) [friend]

Definition at line 214 of file yang.cc.

00215 {
00216         if (v.lenth != mat.nrows)
00217                 error("op*(Vtr, Mtx): Error: Mat. and vec. size do no match.");
00218         Vtr res(mat.ncols, 0.0);
00219         for (int i=0; i<mat.ncols; i++)
00220                 for (int j=0; j<v.lenth; j++)
00221                         res[i] = v.ets[j] * mat.ets[j][i];
00222         return res;
00223 }

Vtr operator* ( const Vtr v1,
const Vtr v2 
) [friend]

Definition at line 113 of file yang.cc.

00113                                               {
00114   int sz = v1.lenth;
00115   if (sz != v2.lenth ) error("bad vtor sizes");
00116   Vtr tm(sz);
00117   for (int i = 0; i < sz; i++)
00118       tm[i] = v1[i]*v2[i];
00119   return tm;
00120 }

Vtr operator* ( const Vtr v,
const double  scalar 
) [friend]

Definition at line 44 of file yang.h.

00044                                                          {
00045   return scalar*v; 
00046 }

Vtr operator* ( const double  scalar,
const Vtr v 
) [friend]

Definition at line 107 of file yang.cc.

00107                                                   {
00108   Vtr tm(v.lenth);
00109   for (int i = 0; i < v.lenth; i++) tm[i] = scalar*v[i];
00110   return tm;
00111 }

Vtr operator+ ( const Vtr v1,
const Vtr v2 
) [friend]

Definition at line 65 of file yang.cc.

00065                                              {          // v=v1+v2
00066   if (v1.lenth != v2.lenth ) error("Vtr::op+: Error Bad vtor sizes");
00067   Vtr sum = v1; // It would cause problem without copy constructor
00068   sum += v2;
00069   return sum;
00070 }

Vtr operator+ ( const Vtr v  )  [friend]

Definition at line 57 of file yang.cc.

00057                              {  // usage: v1 = + v2;
00058   return v;
00059 }

Vtr operator- ( const Vtr v1,
const Vtr v2 
) [friend]

Definition at line 72 of file yang.cc.

00072                                             { // v=v1-v2
00073 //  if (v1.lenth != v2.lenth ) error("bad vtor sizes");
00074   Vtr sum = v1; // It would cause problem without copy constructor
00075   sum -= v2;
00076   return sum;
00077 }

Vtr operator- ( const Vtr v  )  [friend]

Definition at line 61 of file yang.cc.

00061                             {    // usage: v1 = - v2;
00062   return Vtr(v.lenth) - v;
00063 }

Vtr operator/ ( const Vtr v,
const double  scalar 
) [friend]

Definition at line 122 of file yang.cc.

00122                                                   {
00123   if (scalar == 0) error("division by zero in vector-scalar division");
00124   return (1.0/scalar)*v;
00125 }

std::ostream& operator<< ( std::ostream &  s,
const Vtr v 
) [friend]

Definition at line 79 of file yang.cc.

00079                                                       {
00080   for (int i =0; i < v.lenth; i++ ) {
00081     s << v[i] << "  ";
00082     if (i%10 == 9) s << "\n";
00083   }
00084   return s;
00085 }


Member Data Documentation

double* Vtr::ets [private]

Definition at line 16 of file yang.h.

Referenced by maxnorm(), operator*(), operator+=(), operator-=(), operator=(), operator[](), twonorm(), Vtr(), and ~Vtr().

int Vtr::lenth [private]

The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3