JSci.maths
Class DoubleVector

java.lang.Object
  extended byJSci.maths.MathVector
      extended byJSci.maths.DoubleVector
All Implemented Interfaces:
JSci.maths.groups.AbelianGroup.Member, JSci.maths.algebras.BanachSpace.Member, JSci.maths.Member, JSci.maths.algebras.Module.Member, java.io.Serializable, JSci.maths.algebras.VectorSpace.Member
Direct Known Subclasses:
Double2Vector, Double4Vector

public class DoubleVector
extends JSci.maths.MathVector
implements JSci.maths.algebras.BanachSpace.Member

The DoubleVector class encapsulates double vectors. Hendrik added 3 changes: 1. made vector[] public instead of protected 2. removed getComponent() out-of-bounds check (done by java anyways) 3. bugfix in norm(int n), already submitted to author of JSci

Version:
2.2
Author:
Mark Hale, Hendrik Dahlkamp
See Also:
Serialized Form

Field Summary
protected static int ARRAY_1D
          Storage format identifier.
 double[] vector
          Array containing the components of the vector.
 
Fields inherited from class JSci.maths.MathVector
CLASS_SPECIFIC, N, storageFormat
 
Constructor Summary
  DoubleVector(double[] array)
          Constructs a vector by wrapping an array.
  DoubleVector(int dim)
          Constructs an empty vector.
protected DoubleVector(int dim, int storeID)
           
 
Method Summary
 JSci.maths.groups.AbelianGroup.Member add(JSci.maths.groups.AbelianGroup.Member v)
          Returns the addition of this vector and another.
 DoubleVector add(DoubleVector v)
          Returns the addition of this vector and another.
 boolean equals(java.lang.Object a)
          Compares two double vectors for equality.
 double getComponent(int n)
          Returns a component of this vector.
 int hashCode()
          Returns a hashcode for this vector.
 double infNorm()
          Returns the linfinity-norm.
 DoubleVector mapComponents(JSci.maths.Mapping f)
          Applies a function on all the vector components.
 JSci.maths.groups.AbelianGroup.Member negate()
          Returns the negative of this vector.
 double norm()
          Returns the l2-norm (magnitude).
 double norm(int n)
          Returns the ln-norm.
 void normalize()
          Makes the norm of this vector equal to 1.
private  DoubleVector rawAdd(DoubleVector v)
           
private  double rawScalarProduct(DoubleVector v)
           
private  DoubleVector rawSubtract(DoubleVector v)
           
 DoubleVector scalarDivide(double x)
          Returns the division of this vector by a scalar.
 JSci.maths.algebras.VectorSpace.Member scalarDivide(JSci.maths.fields.Field.Member x)
          Returns the division of this vector by a scalar.
 DoubleVector scalarMultiply(double x)
          Returns the multiplication of this vector by a scalar.
 JSci.maths.algebras.Module.Member scalarMultiply(JSci.maths.fields.Ring.Member x)
          Returns the multiplication of this vector by a scalar.
 double scalarProduct(DoubleVector v)
          Returns the scalar product of this vector and another.
 void setComponent(int n, double x)
          Sets the value of a component of this vector.
 JSci.maths.groups.AbelianGroup.Member subtract(JSci.maths.groups.AbelianGroup.Member v)
          Returns the subtraction of this vector by another.
 DoubleVector subtract(DoubleVector v)
          Returns the subtraction of this vector by another.
 JSci.maths.ComplexVector toComplexVector()
          Converts this vector to a complex vector.
 JSci.maths.IntegerVector toIntegerVector()
          Converts this vector to an integer vector.
 java.lang.String toString()
          Returns a comma delimited string representing the value of this vector.
 
Methods inherited from class JSci.maths.MathVector
dimension, getInvalidComponentMsg
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ARRAY_1D

protected static final int ARRAY_1D
Storage format identifier.

See Also:
Constant Field Values

vector

public double[] vector
Array containing the components of the vector.

Constructor Detail

DoubleVector

protected DoubleVector(int dim,
                       int storeID)

DoubleVector

public DoubleVector(int dim)
Constructs an empty vector.

Parameters:
dim - the dimension of the vector.

DoubleVector

public DoubleVector(double[] array)
Constructs a vector by wrapping an array.

Parameters:
array - an assigned value.
Method Detail

equals

public boolean equals(java.lang.Object a)
Compares two double vectors for equality.

Parameters:
a - a double vector.

toString

public java.lang.String toString()
Returns a comma delimited string representing the value of this vector.


hashCode

public int hashCode()
Returns a hashcode for this vector.


toIntegerVector

public JSci.maths.IntegerVector toIntegerVector()
Converts this vector to an integer vector.

Returns:
an integer vector.

toComplexVector

public JSci.maths.ComplexVector toComplexVector()
Converts this vector to a complex vector.

Returns:
a complex vector.

getComponent

public final double getComponent(int n)
Returns a component of this vector.

Parameters:
n - index of the vector component.
Throws:
VectorDimensionException - If attempting to access an invalid component.

setComponent

public void setComponent(int n,
                         double x)
Sets the value of a component of this vector.

Parameters:
n - index of the vector component.
x - a number.
Throws:
VectorDimensionException - If attempting to access an invalid component.

norm

public double norm(int n)
Returns the ln-norm.


norm

public double norm()
Returns the l2-norm (magnitude).

Specified by:
norm in interface JSci.maths.algebras.BanachSpace.Member

normalize

public void normalize()
Makes the norm of this vector equal to 1.


infNorm

public double infNorm()
Returns the linfinity-norm.


negate

public JSci.maths.groups.AbelianGroup.Member negate()
Returns the negative of this vector.

Specified by:
negate in interface JSci.maths.groups.AbelianGroup.Member

add

public JSci.maths.groups.AbelianGroup.Member add(JSci.maths.groups.AbelianGroup.Member v)
Returns the addition of this vector and another.

Specified by:
add in interface JSci.maths.groups.AbelianGroup.Member

add

public DoubleVector add(DoubleVector v)
Returns the addition of this vector and another.

Parameters:
v - a double vector.
Throws:
VectorDimensionException - If the vectors are different sizes.

rawAdd

private DoubleVector rawAdd(DoubleVector v)

subtract

public JSci.maths.groups.AbelianGroup.Member subtract(JSci.maths.groups.AbelianGroup.Member v)
Returns the subtraction of this vector by another.

Specified by:
subtract in interface JSci.maths.groups.AbelianGroup.Member

subtract

public DoubleVector subtract(DoubleVector v)
Returns the subtraction of this vector by another.

Parameters:
v - a double vector.
Throws:
VectorDimensionException - If the vectors are different sizes.

rawSubtract

private DoubleVector rawSubtract(DoubleVector v)

scalarMultiply

public JSci.maths.algebras.Module.Member scalarMultiply(JSci.maths.fields.Ring.Member x)
Returns the multiplication of this vector by a scalar.

Specified by:
scalarMultiply in interface JSci.maths.algebras.Module.Member

scalarMultiply

public DoubleVector scalarMultiply(double x)
Returns the multiplication of this vector by a scalar.

Parameters:
x - a double.

scalarDivide

public JSci.maths.algebras.VectorSpace.Member scalarDivide(JSci.maths.fields.Field.Member x)
Returns the division of this vector by a scalar.

Specified by:
scalarDivide in interface JSci.maths.algebras.VectorSpace.Member

scalarDivide

public DoubleVector scalarDivide(double x)
Returns the division of this vector by a scalar.

Parameters:
x - a double.
Throws:
java.lang.ArithmeticException - If divide by zero.

scalarProduct

public double scalarProduct(DoubleVector v)
Returns the scalar product of this vector and another.

Parameters:
v - a double vector.
Throws:
VectorDimensionException - If the vectors are different sizes.

rawScalarProduct

private double rawScalarProduct(DoubleVector v)

mapComponents

public DoubleVector mapComponents(JSci.maths.Mapping f)
Applies a function on all the vector components.

Parameters:
f - a user-defined function.
Returns:
a double vector.