ClassVec - the model of Linear Algebra with the linear operations
test applet and code is here
/*[class] Vec 5/20/2008 by Classiclll
* the model of Linear Algebra with the linear operations.
* The index of Vecrices is 0-based -- e.g.,
* elem(0) : the left mostelement
* elem(idx) : the (idx+1)th element.
* can solve the polynomial equation, all the roots are complex with DKA method
* v[0]*x^n + v[1]*x^(n-1) + .... + v[n-1]*x^1 = b
* - you can use the convinient, Vec realRoots(Mat root)
* to get unique real roots if exist.
*/
[members]
static final Vec NaN //constant Vec of one Double.NaN(not a number)
[constructer]
Vec() //construct empty
Vec(int length) //construct zero vector sized by "length"
Vec(Vec v) //construct same to v
Vec(double[] d, int length) //construct having d
Vec(Loc v) //construct 3D vector, (x,y,z)
[methods]
<group #1 - Vector Operation - generator>
Vec copy() //return the copy of me.
Vec add(Vec m) //return me[i] + m[i]
Vec add(double d) //return me[i] + d (scalar)
Vec sub(Vec m) //return me[i] - m[i]
Vec sub(double d) //return me[i] - d (scalar)
Vec mul(Vec v) //return me[i] * v[i]
Vec mul(double d) //return me[i] * d (scalar)
Vec div(Vec v) //return me[i] / v[i]
Vec div(double d) //return me[i] / d (scalar)
Vec setSubVec(Vec subVec, int row) //ret[row+i] <= subVec[i][j]
Vec SubVec(int start, int end) //return me[sRow->eRow]
Vec SubVec(int[] selected) //retturn {{.},..{me[selRow][selCol]},..{.}}
Mat transpose() //return the transpose of me.
Vec inverse() //"me" must be square, otherwize null returned
Mat cross(Vec v) //return Mat it's trace has me[i]*v[i]
<group #2 - Scalar - information>
double dot(Vec v) //return sum of me[i] * m[i]
int length() //return the number of elmements
double elem(int idx) //return the specified element
double norm() //return the infinit(=maximum) norm of me.
double normL2() //return the L2 norm of me.
double sqNormL2() //return the sqare of the L2 norm of me.
double dist(Vec v) //return euclid distance (=L2) between v and me.
double dist2(Vec v) //return square of distance between v and me.
boolean equals(Object object) //return value equolity between me and object
boolean hasNaN() //return has me some Double.NaN
boolean hasInf() //return has me some Double.Infinity
boolean isNaN() //return is me containing NaN or Infinity
<group #3 - Utilities - generator>
double[] toArray() //return 2d array of me
Loc toLoc() //return Loc of me (length must be 3)
double[] arrayRef() //retuen the reference to 2d array of "me"
// * modification may cause some trouble.
String toString() //get the string expression of me.
<group #4 - High level operator>
double polyValueAt(double x) //return me[0]*x^n + ... + me[n-1]*x
Vec realRoots(Mat root)
// Returns only unique real root with chopping the small imagenary of solve(b).
Mat solve(double b)
/* Returns the all roots of the following polynomial equation by the DKA Method.
me[0]*x^n + ...+me[k]*x^(n-k)+... + me[n-1]*x - b = 0.
solution matrix has
solution.rowDim() always 2, (number of parts of the complex expression)
solution.colDim() the number of solution pairs
solution[0][k] the real part of (k+1)th solution
solution[1][k] the imaginary part of (k+1)th solution */