![]()
![]()
Include File :cammva.h
A class for a vector of values of type double and whose member functions are operations on vectors. The vectors are column vectors (by default).
The class CAMmvaGraphics provides graphical output routines that accept CAMdoubleVector arguments. Specific functions for CAMdoubleVector are described in "Graphics Functions for CAMdoubleVector".
Chris Anderson © UCLA 8/18/97
CAMdoubleVector v(m); |
A column vector v of size m with index starting at 1. |
CAMdoubleVector v( _(m1,m2) ) ; |
A column vector v with index from m1 to m2._(m1,m2) is a CAMrange object. |
CAMdoubleVector v(m,"row"); |
A row vector v of size m with index starting at 1. |
CAMdoubleVector v( _(m1,m2),"row" ); |
A row vector v with index from m1 to m2. _(m1,m2) is a CAMrange object. |
CAMdoubleVector v; |
A vector v of 0 size (a null vector). |
CAMdoubleVector v = w; |
A vector v which is a copy of a vector w. |
Often, when programming with CAMdoubleVector objects one desires to change the structure of an existing object. The initialize function allows one to re-initialize an existing object to have a different structure. The initialization process discards any data previously associated with the object. The new data values are initialized to 0.
Initialize
| v.initialize(); | v is initialized to a null vector. |
| v.initialize(m); | v is initialized to a vector with m elements. |
| v.initialize(_(m1,m2)); | v is initialized to a vector whose index runs from m1 to m2. _(m1,m2) is a CAMrange object. |
| v.initialize(T); | v is initialized as a copy of vector T. |
= |
Assignment. v = w; assigns the values in the vector w to v. |
+ |
Addition. v = w + z; assigns the sum of w + z to v. |
- |
Subtraction. v = w - z; assigns the difference of w - z to v. |
* |
Multiplication. v = M*w assigns the CAMdoubleVector v the product of the CAMdoubleMatrix M times the CAMdoubleVector w. If dimensionally correct, then v = w*z holds for CAMdoubleVector objects. The result is a CAMdoubleMatrix. (For inner products, use the dot(…) utility function). |
~ |
Transpose. w = ~v; assigns the transpose of v to w. |
-() |
Negation. w = -v; assigns the opposite of the values in v to w. |
+= |
Incremental addition. v+=w; is equivalent to v = v+ w; |
-= |
Incremental subtraction . v-=w is equivalent to v = v - w; |
<< |
Vector output. cout << v; outputs the vector to the output stream cout. |
>> |
Vector input. cin >> v; inputs the vector from the input stream cin. |
The operators in the table above are applicable whenever the expression in which they are contained makes mathematical sense, i.e. the dimensions and the type of the object are correct.
Scaler multiplication and division of vector objects is allowed (except in the case of a one element vector, then the assignment, addition, or subtraction with a scaler using the operators -, +, and = results in an error. The member functions setToValue(), plusValue(), minusValue() are used for such operations.)
v(i); |
The element of the vector v whose index is i. |
v(_(i1,i2)); |
The subvector of the vector v with indices from i1 to i2. _(i1,i2) is a CAMrange object. |
Each of the access expressions can occur on the left as well as the right hand side of an assignment statement. So, for example, the statement
v(_(2,4)) = w;
assigns the values of the vector w to the second through the fourth elements of v.
There is one syntax construction in C++ which does not work when dealing with sub-vectors - ``multiple assignment''
statements of the form v = w = z. For example, the statement
v = w(_(2,3) = z;
will cause the compiler to issue an error and stop. This is an artifact of our particular implementation of these classes.
n = v.getIndexCount(); |
n (a long) is assigned the number of elements in v. |
n = v.getIndexBase(); |
n (a long) is assigned the starting index of v. |
n = v.getIndexBound(); |
n (a long) is assigned the ending index of v. |
v.setIndexBase(n); |
The starting index of v is set to the long n |
d = v.getDataPointer(); |
The pointer d (of type double*) is set to the address of the first element of the data in v. The data is stored by columns (FORTRAN storage convention). |
d = v.dot(w); |
A double d is assigned the dot product of the vectors v and w. |
d = v.max(); |
A double d is assigned the maximum of the elements of the v. |
d = v.min(); |
A double d is assigned the minimum of the elements of v. |
d = v.maxAbs(); |
A double d is assigned the maximum of the absolute value of the elements of v. |
d = v.minAbs(); |
A double d is assigned the minimum of the absolute value of the elements of CAMdoubleVector v. |
v.setToValue(d); |
Every element of v is assigned the value the double d. |
r = v.plusValue(d); |
r is set to the vector obtained by adding d to every element of v. |
r = v.minusValue(d); |
r is set to the vector obtained by subtracting d from every element of v. |