Public Member Functions | Private Attributes | Friends

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.

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

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

Definition at line 23 of file yang.cc.

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

Vtr::Vtr ( const Vtr v  ) 

Definition at line 28 of file yang.cc.

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

Vtr::~Vtr (  )  [inline]

Definition at line 21 of file yang.h.

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


Member Function Documentation

double Vtr::maxnorm (  )  const

Definition at line 100 of file yang.cc.

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

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

Definition at line 45 of file yang.cc.

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

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

Definition at line 51 of file yang.cc.

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

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

Definition at line 37 of file yang.cc.

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

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

Definition at line 26 of file yang.h.

{ 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().

{ return lenth; }                 // return length of vector

double Vtr::twonorm (  )  const

Definition at line 87 of file yang.cc.

                         {
  double norm = std::abs(ets[0]);
  for (int i = 1; i < lenth; i++) {
    double vi = std::abs(ets[i]);
    if (norm < 100) norm = std::sqrt(norm*norm + vi*vi);
    else {  // to avoid overflow for fn "sqrt" when norm is large
      double tm = vi/norm;
      norm *= std::sqrt(1.0 + tm*tm);
    }
  }
  return norm;
}


Friends And Related Function Documentation

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

Definition at line 127 of file yang.cc.

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

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

Definition at line 113 of file yang.cc.

                                              {
  int sz = v1.lenth;
  if (sz != v2.lenth ) error("bad vtor sizes");
  Vtr tm(sz);
  for (int i = 0; i < sz; i++)
      tm[i] = v1[i]*v2[i];
  return tm;
}

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

Definition at line 214 of file yang.cc.

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

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

Definition at line 107 of file yang.cc.

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

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

Definition at line 44 of file yang.h.

                                                         {
  return scalar*v; 
}

Vtr operator+ ( const Vtr v  )  [friend]

Definition at line 57 of file yang.cc.

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

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

Definition at line 65 of file yang.cc.

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

Vtr operator- ( const Vtr v  )  [friend]

Definition at line 61 of file yang.cc.

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

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

Definition at line 72 of file yang.cc.

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

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

Definition at line 122 of file yang.cc.

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

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

Definition at line 79 of file yang.cc.

                                                      {
  for (int i =0; i < v.lenth; i++ ) {
    s << v[i] << "  ";
    if (i%10 == 9) s << "\n";
  }
  return s;
}


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: