sugr.linalg
Class VectorImplJama

java.lang.Object
  extended bysugr.linalg.VectorImplJama
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, Vector

public class VectorImplJama
extends java.lang.Object
implements Vector

Vector class. Contains operations of linear algebra: Addition/Substraction, Multiplication, get/set-methods (all double precision floating points), printing.

Construction of vectors is also possible. You are allowed to use LinearAlgebraFactory-methods for constructing matrices and vector. For more information about this class, you are invited to read more in sugr.linalg.LinearAlgebraFactory

Just a note: In further documentation, vector s is synonym for this vector, e.g.:

 		Vector firstVector; 
 		Vector secondVector;
 		Vector r = firstVector.add(secondVector);
 
means for add(Vector v): firstVector is this Vector = s, secondVector is v

Version:
1.0.1 (24.2.2003) - Fixed: in VectorImplJama(double[] values) was a comparison fault so that an IndexOutOfBoundException occured

Author:
Norbert Daniel Goldbach, Norbert Fischer
See Also:
Serialized Form

Field Summary
protected  Jama.Matrix impl
          Jama.Matrix is embedded into this class - all operations are mapped to that.
private static long serialVersionUID
          Class version number for serialization
 
Constructor Summary
VectorImplJama()
          standard constructor
VectorImplJama(double[] values)
          create a new vector by a given double precision floating point array.
VectorImplJama(int size)
          Creates a new vector containing only zeros.
VectorImplJama(Vector v)
          create r from s.
 
Method Summary
 java.lang.Object clone()
          Clone a vector.
 Vector copy()
          Copies s into a new vector r
 Vector crossProduct(Vector v)
          calulates the cross product: r = s x v.
 boolean equals(java.lang.Object obj)
          Test, whether s and v are identical or not
 double get(int pos)
          Gets an element from s
 Vector get(int i0, int i1)
          Get a part of the vector.
 int getDim()
          Returns the dimension of s
 double getLength()
          Calculates the length of s.
 Matrix getMatrix()
          Creates a matrix from s
This is a "kind" of typecast.
 Vector minus(Vector v)
          Substracts to vectors: r = s-v
 Vector mult(double f)
          Multiplication with scalar: r = a*s
 double normF()
          Calculates the Frobenius norm of a vector, which is the same as the getLength().
 double normM()
          Calculates the maximum norm of a vector
 Vector plus(Vector v)
          Add two vectors: r = s+v
 void print()
          Prints this matrix to stdout
 void print(int w, int d)
          Prints this matrix to stdout
Note:It may be useful to select w > d.
 void printMatlab()
          Prints this matrix in MATLAB format to stdout
 double scalarmult(Vector v)
          scalarmultiplication (or dot product)of two vectors: a = s*v, where a is a scalar value
 void set(int pos, double value)
          Set an element of s
 void set(int pos, Vector v)
          Set a part of a vector
 Matrix SkewSym()
          Creates a skew-symmetrix matrix from s. s must have dimension 3 to do that.
 java.lang.String toString()
          Delivers a string with the elements of the matrix.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Class version number for serialization

See Also:
Constant Field Values

impl

protected Jama.Matrix impl
Jama.Matrix is embedded into this class - all operations are mapped to that.

Constructor Detail

VectorImplJama

public VectorImplJama(int size)
Creates a new vector containing only zeros.

Parameters:
size - Dimension the vector should have

VectorImplJama

public VectorImplJama(double[] values)
create a new vector by a given double precision floating point array. It has dimension=#elements in array

Parameters:
values - given in double

VectorImplJama

public VectorImplJama(Vector v)
create r from s. Functionally it works like copy


VectorImplJama

public VectorImplJama()
standard constructor

Method Detail

plus

public Vector plus(Vector v)
Add two vectors: r = s+v

Specified by:
plus in interface Vector
Parameters:
v - vector to add
Returns:
s+v

minus

public Vector minus(Vector v)
Substracts to vectors: r = s-v

Specified by:
minus in interface Vector
Parameters:
v - vector to substract
Returns:
s-v

scalarmult

public double scalarmult(Vector v)
scalarmultiplication (or dot product)of two vectors: a = s*v, where a is a scalar value

Specified by:
scalarmult in interface Vector
Parameters:
v - vector to scalarmultiplicate
Returns:
s*v, where a = s_0*v_0 + s_1*v_1 + ... + s_n*v_n as double

crossProduct

public Vector crossProduct(Vector v)
calulates the cross product: r = s x v.

Specified by:
crossProduct in interface Vector
Parameters:
v - vector to create cross product with
Returns:
a Vector orthogonal to both s and v

mult

public Vector mult(double f)
Multiplication with scalar: r = a*s

Specified by:
mult in interface Vector
Parameters:
f - scalar value
Returns:
a Vector multiplicated with a scalar

copy

public Vector copy()
Copies s into a new vector r

Specified by:
copy in interface Vector
Returns:
a Vector r independent from s with s=r

set

public void set(int pos,
                double value)
Set an element of s

Specified by:
set in interface Vector
Parameters:
pos - Position to set a new value. First position is 0
value - new value to set

set

public void set(int pos,
                Vector v)
Set a part of a vector

Specified by:
set in interface Vector
Parameters:
pos - begining position (inclusive)
v - vector which hold the values to be set. All the values from the vector are copied to the target.

get

public double get(int pos)
Gets an element from s

Specified by:
get in interface Vector
Parameters:
pos - Position to get element from. Starts with 0
Returns:
the element as an double

getDim

public int getDim()
Returns the dimension of s

Specified by:
getDim in interface Vector
Returns:
a int containing the dimension

getLength

public double getLength()
Calculates the length of s. This is the same as the Frobenius norm.

Specified by:
getLength in interface Vector
Returns:
a = sqrt(s*s)

print

public void print(int w,
                  int d)
Prints this matrix to stdout
Note:It may be useful to select w > d. A common value is w=5, d=3

Specified by:
print in interface Vector
Parameters:
w - describes the width of a single element
d - number of decimals after comma

print

public void print()
Prints this matrix to stdout

Specified by:
print in interface Vector

printMatlab

public void printMatlab()
Prints this matrix in MATLAB format to stdout

Specified by:
printMatlab in interface Vector

toString

public java.lang.String toString()
Delivers a string with the elements of the matrix.

Specified by:
toString in interface Vector
Returns:
a string for printing

equals

public boolean equals(java.lang.Object obj)
Test, whether s and v are identical or not

Specified by:
equals in interface Vector
Parameters:
obj - vector to test
Returns:
boolean value: true, if identical, otherwise false

getMatrix

public Matrix getMatrix()
Creates a matrix from s
This is a "kind" of typecast. Useful for matrix-/vectormultiplication

Specified by:
getMatrix in interface Vector
Returns:
vector as a matrix

SkewSym

public Matrix SkewSym()
Creates a skew-symmetrix matrix from s. s must have dimension 3 to do that.
 e.g.:         | a |                              |  0 -c   b |
       if  s = | b | , then s.Skewsym() returns   |  c  0  -a |
               | c |                              | -b  a   0 |
 
This matrix can be read as a cross product.

Specified by:
SkewSym in interface Vector
Returns:
returns skewsym from 3-dim vector. matrix has rank 2

get

public Vector get(int i0,
                  int i1)
Get a part of the vector.

Specified by:
get in interface Vector
Parameters:
i0 - index of first vector element
i1 - index of the last vector element
Returns:
a vector which is a part of the original vector.

normF

public double normF()
Calculates the Frobenius norm of a vector, which is the same as the getLength().

Specified by:
normF in interface Vector
Returns:
a = sqrt(s*s)

normM

public double normM()
Calculates the maximum norm of a vector

Specified by:
normM in interface Vector
Returns:
a = max|v_i|

clone

public java.lang.Object clone()
Clone a vector.

Specified by:
clone in interface Vector
Returns:
a copy of the vector.