Package pulse.math.linear
Class Vector
- java.lang.Object
-
- pulse.math.linear.Vector
-
- All Implemented Interfaces:
Serializable
public class Vector extends Object implements Serializable
This is a general class for
Vectoroperations useful for optimisers and ODE solvers.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intdimension()The dimension is simply the number of elements in aVectordoubledistanceToSq(Vector v)Calculates the squared distance fromthis Vectortov(which is the squared length of the connectingVector).doubledot(Vector v)Calculates the scalar product ofthisandv.booleanequals(Object o)Checks ifois logically equivalent to an instance of this class.doubleget(int index)Gets the component ofthis Vectorspecified byindexdouble[]getData()Vectorinverted()Creates a newVectorbased onthisone, all elements of which are inverted, i.e.doublelength()Calculates the length, which is represented by the square-root of the squared length.doublelengthSq()The squared length of this vector is the dot product of this vector by itself.doublemaxAbsComponent()Determines the maximum absolute value of the vector components.VectormultComponents(Vector v)Component-wise vector multiplicationVectormultiply(double f)Performs an element-wise multiplication byf.Vectornormalise()Performs normalisation, e.g.static Vectorrandom(int n, double min, double max)Creates a vector with random coordinates confined within [min;max]voidset(int index, double value)Sets the component ofthis Vectorspecified byindextovalue.Vectorsubtract(Vector v)Performs an element-wise subtraction ofvfromthis.Vectorsum(Vector v)Performs an element-wise summation ofthisandv.StringtoString()Defines the string representation of the current instance of the class.
-
-
-
Constructor Detail
-
Vector
public Vector(double[] x)
Constructs a new vector specified by the argument array- Parameters:
x- an array of double
-
Vector
public Vector(int n)
Creates a zeroVector.- Parameters:
n- the dimension of theVector.
-
Vector
public Vector(Vector v)
Copy constructor.- Parameters:
v- The vector to be copied
-
-
Method Detail
-
inverted
public Vector inverted()
Creates a newVectorbased onthisone, all elements of which are inverted, i.e. .- Returns:
- a generalised inversion of
this Vector.
-
dimension
public final int dimension()
The dimension is simply the number of elements in aVector- Returns:
- the integer dimension
-
sum
public Vector sum(Vector v)
Performs an element-wise summation ofthisandv.- Parameters:
v- anotherVectorwith the same number of elements.- Returns:
- the result of the summation.
-
subtract
public Vector subtract(Vector v)
Performs an element-wise subtraction ofvfromthis.- Parameters:
v- anotherVectorwith the same number of elements.- Returns:
- the result of subtracting
vfromthis. - Throws:
IllegalArgumentException- f the dimension ofthisandvare different.
-
multiply
public Vector multiply(double f)
Performs an element-wise multiplication byf.- Parameters:
f- a double value.- Returns:
- a new
Vector, all elements of which will be multiplied byf.
-
random
public static Vector random(int n, double min, double max)
Creates a vector with random coordinates confined within [min;max]- Parameters:
n- the vector dimensionmin- upper bound for the random number generatormax- lower bound for the random generator generator- Returns:
- the randomised vector
-
dot
public double dot(Vector v)
Calculates the scalar product ofthisandv.- Parameters:
v- anotherVectorwith the same dimension.- Returns:
- the dot product of
thisandv.
-
length
public double length()
Calculates the length, which is represented by the square-root of the squared length.- Returns:
- the calculated length.
- See Also:
lengthSq()
-
lengthSq
public double lengthSq()
The squared length of this vector is the dot product of this vector by itself.- Returns:
- the squared length.
-
normalise
public Vector normalise()
Performs normalisation, e.g. scalar multiplication ofthisby the multiplicative inverse ofthis Vector's length.- Returns:
- a normalised
Vectorobtained fromthis.
-
distanceToSq
public double distanceToSq(Vector v) throws IllegalArgumentException
Calculates the squared distance fromthis Vectortov(which is the squared length of the connectingVector).- Parameters:
v- anotherVector.- Returns:
- the squared length of the connecting
Vector. - Throws:
IllegalArgumentException- f the dimension ofthisandvare different.
-
get
public double get(int index)
Gets the component ofthis Vectorspecified byindex- Parameters:
index- the index of the component- Returns:
- a double value, representing the value of the component
-
set
public void set(int index, double value)Sets the component ofthis Vectorspecified byindextovalue.- Parameters:
index- the index of the component.value- a new value that will replace the old one.
-
toString
public String toString()
Defines the string representation of the current instance of the class.
-
equals
public boolean equals(Object o)
Checks ifois logically equivalent to an instance of this class.
-
maxAbsComponent
public double maxAbsComponent()
Determines the maximum absolute value of the vector components.- Returns:
- a component having the maximum absolute value.
-
getData
public double[] getData()
-
-