Vtr Class Reference
#include <yang.h>
List of all members.
Public Member Functions |
| Vtr (int, double *) |
| Vtr (int, double=0) |
| Vtr (const Vtr &) |
| ~Vtr () |
Vtr & | operator= (const Vtr &) |
Vtr & | operator+= (const Vtr &) |
Vtr & | operator-= (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 }
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] |
int Vtr::size |
( |
|
) |
const [inline] |
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 {
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 {
00066 if (v1.lenth != v2.lenth ) error("Vtr::op+: Error Bad vtor sizes");
00067 Vtr sum = v1;
00068 sum += v2;
00069 return sum;
00070 }
Vtr operator+ |
( |
const Vtr & |
v |
) |
[friend] |
Definition at line 57 of file yang.cc.
00057 {
00058 return v;
00059 }
Vtr operator- |
( |
const Vtr & |
v1, |
|
|
const Vtr & |
v2 | |
|
) |
| | [friend] |
Definition at line 72 of file yang.cc.
00072 {
00073
00074 Vtr sum = v1;
00075 sum -= v2;
00076 return sum;
00077 }
Vtr operator- |
( |
const Vtr & |
v |
) |
[friend] |
Definition at line 61 of file yang.cc.
00061 {
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
Definition at line 15 of file yang.h.
Referenced by dot(), maxnorm(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator<<(), operator=(), size(), twonorm(), and Vtr().
The documentation for this class was generated from the following files: