maspack.matrix
Class VectorNd

java.lang.Object
  extended by maspack.matrix.VectorBase
      extended by maspack.matrix.VectorNd
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Vector, Clonable

public class VectorNd
extends VectorBase
implements java.io.Serializable, Clonable

Implements general vectors, along with their most commonly used operations.

These vectors can be resized, either explicitly through a call to setSize, or implicitly through operations that require the vector size to be modified.

See Also:
Serialized Form

Constructor Summary
VectorNd()
          Creates a vector with an initial size of zero.
VectorNd(double[] values)
          Creates a vector from an array of doubles.
VectorNd(int size)
          Creates a vector of a specific size, and initializes its elements to 0.
VectorNd(int size, double[] values)
          Creates a vector of a specific size, and initializes its elements from an array of values.
VectorNd(Matrix M)
          Creates a vector whose size and elements match a particular Matrix.
VectorNd(Vector v)
          Creates a vector whose size and elements are the same as an existing Vector.
 
Method Summary
 void absolute()
          Sets the elements of this vector to their absolute values.
 void absolute(VectorNd v1)
          Sets the elements of this vector to the absolute value of v1.
 void add(int i, double value)
          Adds a value to the i-th element of this vector.
 void add(VectorNd v1)
          Adds this vector to v1 and places the result in this vector.
 void add(VectorNd v1, VectorNd v2)
          Adds vector v1 to v2 and places the result in this vector.
 void addNoise(double eps)
          Adds a random perturbation to this vector, in the range [-lim,lim], where
 void addNoise(double eps, java.util.Random generator)
          Adds a random perturbation to this vector, in the range [-lim,lim], where
 int adjustSize(int inc)
           
 double angle(VectorNd v1)
          Returns the angle between this vector and v1.
 void append(double value)
          Appends a value to the end of this vector, increasing its size by one.
 VectorNd clone()
           
 void combine(double s1, VectorNd v1, double s2, VectorNd v2)
          Computes s1 v1 + s2 v2 and places the result in this vector.
 double distance(VectorNd v)
          Returns the distance between this vector and another.
 double dot(VectorNd v1)
          Returns the dot product of this vector and v1.
 boolean epsilonEquals(VectorNd v1, double eps)
          Returns true if the elements of this vector equal those of vector v1within a prescribed tolerance epsilon.
 boolean equals(VectorNd v1)
          Returns true if the elements of this vector exactly equal those of vector v1.
 void get(double[] values)
          Copies the elements of this vector into an array of doubles.
 void get(double[] values, int idx)
          Copies the elements of this vector into an array of doubles, starting at a particular location.
 double get(int i)
          Gets a single element of this vector.
 double[] getBuffer()
          Returns the internal buffer used to store the elements in this vector.
 int getCapacity()
           
 void getSubVector(int[] idxs, VectorNd v1)
          Gets a subset of the values of this vector, whose indices are specified by idxs, and places them in v1.
 void getSubVector(int off, VectorNd v1)
          Gets a subset of the values of this vector, beginning at a specified offset, and places them in v1.
static void hermiteInterpolate(VectorNd pr, VectorNd p0, VectorNd v0, VectorNd p1, VectorNd v1, double s, double h)
          Interpolates the value at a location along a cubic Hermite spline.
 double infinityNorm()
          Returns the infinity norm of this vector.
 void interpolate(double s, VectorNd v1)
          Computes the interpolation (1-s) this + s v1 and places the result in this vector.
 void interpolate(VectorNd v1, double s, VectorNd v2)
          Computes the interpolation (1-s) v1 + s v2 and places the result in this vector.
 boolean isFixedSize()
          Returns true if this vector is of fixed size.
 boolean isRowVector()
           
 void max(VectorNd v)
          Computes the element-wise maximum of this vector and vector v and places the result in this vector.
 double maxElement()
          Returns the maximum element value of this vector.
 int maxIndex()
          Returns the index of the maximum element of this vector.
 double mean()
          Returns the mean value of the elements of this vector.
 void min(VectorNd v)
          Computes the element-wise minimum of this vector and vector v and places the result in this vector.
 double minElement()
          Returns the minimum element value of this vector.
 int minIndex()
          Returns the index of the minimum element of this vector.
 void mul(Matrix M, VectorNd b)
          Multiplies matrix M by the vector b and places the result in this vector.
 void mulTranspose(Matrix M, VectorNd b)
          Multiplies the transpose of matrix M by the vector b and places the result in this vector.
 void negate()
          Negates this vector in place.
 void negate(VectorNd v1)
          Sets this vector to the negative of v1.
 double norm()
          Returns the 2 norm of this vector.
 void normalize()
          Normalizes this vector in place.
 void normalize(VectorNd v1)
          Computes a unit vector in the direction of v1 and places the result in this vector.
 double normSquared()
          Returns the square of the 2 norm of this vector.
 double oneNorm()
          Returns the 1 norm of this vector.
 void permute(int[] permutation)
          Rearrange the elements of this vector according to the specified permutation, such that each element i is replaced by element permutation[i].
 void scale(double s)
          Scales the elements of this vector by s.
 void scale(double s, VectorNd v1)
          Scales the elements of vector v1 by s and places the results in this vector.
 void scaledAdd(double s, VectorNd v1)
          Computes s v1 and adds the result to this vector.
 void scaledAdd(double s, VectorNd v1, VectorNd v2)
          Computes s v1 + v2 and places the result in this vector.
 void set(double[] values)
          Sets the elements of this vector from an array of doubles.
 void set(double[] values, int idx)
          Sets the elements of this vector from an array of doubles, starting from a particular location.
 void set(int i, double value)
          Sets a single element of this vector.
 void set(VectorNd v1)
          Sets the size and values of this vector to those of v1.
 void setBuffer(int size, double[] buffer)
          Explicitly sets the size and internal buffer associated with this vector.
 void setCapacity(int newcap)
           
 void setRandom()
          Sets the elements of this vector to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
 void setRandom(double lower, double upper)
          Sets the elements of this vector to uniformly distributed random values in a specified range.
 void setRandom(double lower, double upper, java.util.Random generator)
          Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.
 boolean setRowVector(boolean isRow)
           
 void setSize(int newSize)
          Sets the size of this vector.
 void setSubVector(int[] idxs, VectorNd v1)
          Sets a subset of the values of this vector, whose indices are specified by idxs, to the values of v1.
 void setSubVector(int off, VectorNd v1)
          Sets a subset of the values of this vector, beginning at a specified offset, to the values of v1.
 void setZero()
          Sets the elements of this vector to zero.
 int size()
          Returns the size of this vector.
 void sort()
          Sorts the contents of this vector by element value, from largest to smallest value.
 void sort(VectorNd v1)
          Sorts the contents of vector v1 by element value, from largest to smallest value, and places the result into this vector.
 void sub(VectorNd v1)
          Subtracts v1 from this vector and places the result in this vector.
 void sub(VectorNd v1, VectorNd v2)
          Subtracts vector v1 from v2 and places the result in this vector.
 double sum()
          Returns the sum of all the elements in this vector.
 void unsetBuffer()
          Removes an explicit buffer provided for this vector and replaces it with a default implicit buffer.
 
Methods inherited from class maspack.matrix.VectorBase
containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasNaN, isColumnVectorStringsVertical, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, toString, toString, toString, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VectorNd

public VectorNd()
Creates a vector with an initial size of zero.


VectorNd

public VectorNd(int size)
         throws ImproperSizeException
Creates a vector of a specific size, and initializes its elements to 0. It is legal to create a vector with a size of zero.

Parameters:
size - size of the vector
Throws:
ImproperSizeException - if size is negative

VectorNd

public VectorNd(int size,
                double[] values)
         throws ImproperSizeException
Creates a vector of a specific size, and initializes its elements from an array of values.

Parameters:
size - size of the vector
values - element values for the new vector
Throws:
ImproperSizeException - if size is negative

VectorNd

public VectorNd(double[] values)
Creates a vector from an array of doubles. The vector size is determined by the size of this array.

Parameters:
values - element values for the new vector

VectorNd

public VectorNd(Vector v)
Creates a vector whose size and elements are the same as an existing Vector.

Parameters:
v - vector object to be copied.

VectorNd

public VectorNd(Matrix M)
Creates a vector whose size and elements match a particular Matrix.

Parameters:
M - matrix object to be copied.
Throws:
ImproperSizeException - if the matrix cannot be interpreted as a row or column vector.
Method Detail

getBuffer

public double[] getBuffer()
Returns the internal buffer used to store the elements in this vector. When possible, applications should access the vector elements using the various set and get methods. However, if efficiency requires it, this buffer can be used directly.

Note that the buffer may be larger than the vector. The i-th element in the vector corresponds to the i-th entry in the buffer.

If this vector is resized, then the internal buffer may change and the buffer previously returned by this routine may no longer be valid.

Returns:
internal buffer for this vector
See Also:
setBuffer(int, double[])

size

public int size()
Returns the size of this vector.

Specified by:
size in interface Vector
Specified by:
size in class VectorBase
Returns:
size of the vector

isFixedSize

public boolean isFixedSize()
Returns true if this vector is of fixed size. In the present implementation, VectorNd objects always have variable size, and so this routine always returns false.

Specified by:
isFixedSize in interface Vector
Overrides:
isFixedSize in class VectorBase
Returns:
true if this vector is of fixed size
See Also:
setSize(int)

setSize

public void setSize(int newSize)
             throws ImproperSizeException
Sets the size of this vector. This operation may enlarge the internal buffer associated with this vector, invalidating buffers previously returned by getBuffer.

If a vector is resized, then previous element values which are still within the new vector dimension are preserved. Other (new) element values are undefined.

Specified by:
setSize in interface Vector
Overrides:
setSize in class VectorBase
Parameters:
newSize - new vector size
Throws:
ImproperSizeException - if this vector has an explicit internal buffer and that buffer is too small for the requested size
See Also:
Vector.isFixedSize()

adjustSize

public int adjustSize(int inc)
               throws ImproperSizeException
Throws:
ImproperSizeException

getCapacity

public int getCapacity()

setCapacity

public void setCapacity(int newcap)

setBuffer

public void setBuffer(int size,
                      double[] buffer)
Explicitly sets the size and internal buffer associated with this vector. Any previous values will be discarded, and the vector will assume the new values presently contained within the buffer. The length of buffer must equal or exceed the specified size. The vector can continue to be resized as long as the requested sizes do not exceed the buffer size.

Parameters:
size - new vector size
buffer - explicit buffer for this vector
Throws:
ImproperSizeException - if the specified buffer is too small for the requested size
See Also:
unsetBuffer()

unsetBuffer

public void unsetBuffer()
Removes an explicit buffer provided for this vector and replaces it with a default implicit buffer. The vector retains its present size but all values are replaced with zero.

Throws:
java.lang.IllegalStateException - if this vector does not have an explicit buffer given by setBuffer
See Also:
setBuffer(int, double[])

get

public double get(int i)
Gets a single element of this vector.

Specified by:
get in interface Vector
Specified by:
get in class VectorBase
Parameters:
i - element index
Returns:
element value

get

public void get(double[] values)
Copies the elements of this vector into an array of doubles.

Specified by:
get in interface Vector
Overrides:
get in class VectorBase
Parameters:
values - array into which values are copied

get

public void get(double[] values,
                int idx)
Copies the elements of this vector into an array of doubles, starting at a particular location.

Parameters:
values - array into which values are copied
idx - starting point within values where copying should begin

set

public void set(int i,
                double value)
Sets a single element of this vector.

Specified by:
set in interface Vector
Specified by:
set in class VectorBase
Parameters:
i - element index
value - element value

append

public void append(double value)
Appends a value to the end of this vector, increasing its size by one. If the vector's capacity (i.e., the length of the underlying array) needs to be increased, this is done by an extended amount in order to reduce the overall number of capacity increases that may be incurred by a sequence of append calls.

Parameters:
value - value to append to the end of this vector
Throws:
ImproperSizeException - if the capacity needs to be increased but the internal buffer is explicit and so cannot be increased.

set

public void set(double[] values)
Sets the elements of this vector from an array of doubles.

Specified by:
set in interface Vector
Overrides:
set in class VectorBase
Parameters:
values - array from which values are copied

set

public void set(double[] values,
                int idx)
Sets the elements of this vector from an array of doubles, starting from a particular location.

Parameters:
values - array into which values are copied
idx - starting point within values from which copying should begin

set

public void set(VectorNd v1)
Sets the size and values of this vector to those of v1.

Parameters:
v1 - vector whose size and values are copied
Throws:
ImproperSizeException - if this vector needs resizing but is of fixed size

getSubVector

public void getSubVector(int off,
                         VectorNd v1)
Gets a subset of the values of this vector, beginning at a specified offset, and places them in v1.

Parameters:
off - offset where copying should begin in this vector
v1 - vector returning the sub-vector values
Throws:
ImproperSizeException - if this vector is not large enough to accomodate the specified subvector

setSubVector

public void setSubVector(int off,
                         VectorNd v1)
Sets a subset of the values of this vector, beginning at a specified offset, to the values of v1.

Parameters:
off - offset where copying should begin in this vector
v1 - vector whose values are copied
Throws:
ImproperSizeException - if this vector is not large enough to accomodate the specified subvector

getSubVector

public void getSubVector(int[] idxs,
                         VectorNd v1)
Gets a subset of the values of this vector, whose indices are specified by idxs, and places them in v1.

Parameters:
idxs - indices of the values in this vector that are to be obtained
v1 - vector returning the sub-vector values
Throws:
ImproperSizeException - if the size of idxs is less than v1
java.lang.ArrayIndexOutOfBoundsException - if any of the indices in idxs are out of bounds

setSubVector

public void setSubVector(int[] idxs,
                         VectorNd v1)
Sets a subset of the values of this vector, whose indices are specified by idxs, to the values of v1.

Parameters:
idxs - indices of the values in this vector that are to be set
v1 - vector containing the sub-vector values
Throws:
ImproperSizeException - if the size of idxs is less than v1
java.lang.ArrayIndexOutOfBoundsException - if any of the indices in idxs are out of bounds

add

public void add(VectorNd v1,
                VectorNd v2)
         throws ImproperSizeException
Adds vector v1 to v2 and places the result in this vector. This vector is resized if necessary.

Parameters:
v1 - left-hand vector
v2 - right-hand vector
Throws:
ImproperSizeException - if v1 and v2 have different sizes, or if this vector needs resizing but is of fixed size

add

public void add(VectorNd v1)
         throws ImproperSizeException
Adds this vector to v1 and places the result in this vector.

Parameters:
v1 - right-hand vector
Throws:
ImproperSizeException - if v1 has a size less than this vector

add

public void add(int i,
                double value)
Adds a value to the i-th element of this vector.

Parameters:
i - index of the element
value - value to be added

sub

public void sub(VectorNd v1,
                VectorNd v2)
         throws ImproperSizeException
Subtracts vector v1 from v2 and places the result in this vector. This vector is resized if necessary.

Parameters:
v1 - left-hand vector
v2 - right-hand vector
Throws:
ImproperSizeException - if v1 and v2 have different sizes, or if this vector needs resizing but is of fixed size

sub

public void sub(VectorNd v1)
         throws ImproperSizeException
Subtracts v1 from this vector and places the result in this vector.

Parameters:
v1 - right-hand vector
Throws:
ImproperSizeException - if v1 has a size less than this vector

negate

public void negate(VectorNd v1)
Sets this vector to the negative of v1. This vector is resized if necessary.

Parameters:
v1 - vector to negate
Throws:
ImproperSizeException - if this vector needs resizing but is of fixed size

negate

public void negate()
Negates this vector in place.


scale

public void scale(double s)
Scales the elements of this vector by s.

Parameters:
s - scaling factor

scale

public void scale(double s,
                  VectorNd v1)
Scales the elements of vector v1 by s and places the results in this vector. This vector is resized if necessary.

Parameters:
s - scaling factor
v1 - vector to be scaled
Throws:
ImproperSizeException - if this vector needs resizing but is of fixed size

interpolate

public void interpolate(VectorNd v1,
                        double s,
                        VectorNd v2)
                 throws ImproperSizeException
Computes the interpolation (1-s) v1 + s v2 and places the result in this vector. This vector is resized if necessary.

Parameters:
v1 - left-hand vector
s - interpolation factor
v2 - right-hand vector
Throws:
ImproperSizeException - if v1 and v2 have different sizes, or if this vector needs resizing but is of fixed size

interpolate

public void interpolate(double s,
                        VectorNd v1)
                 throws ImproperSizeException
Computes the interpolation (1-s) this + s v1 and places the result in this vector.

Parameters:
s - interpolation factor
v1 - right-hand vector
Throws:
ImproperSizeException - if v1 has a size less than this vector

scaledAdd

public void scaledAdd(double s,
                      VectorNd v1,
                      VectorNd v2)
               throws ImproperSizeException
Computes s v1 + v2 and places the result in this vector. This vector is resized if necessary.

Parameters:
s - scaling factor
v1 - vector to be scaled
v2 - vector to be added
Throws:
ImproperSizeException - if v1 and v2 have different sizes, or if this vector needs resizing but is of fixed size

scaledAdd

public void scaledAdd(double s,
                      VectorNd v1)
               throws ImproperSizeException
Computes s v1 and adds the result to this vector.

Parameters:
s - scaling factor
v1 - vector to be scaled and added
Throws:
ImproperSizeException - if v1 has a size less than this vector

combine

public void combine(double s1,
                    VectorNd v1,
                    double s2,
                    VectorNd v2)
             throws ImproperSizeException
Computes s1 v1 + s2 v2 and places the result in this vector. This vector is resized if necessary.

Parameters:
s1 - left-hand scaling factor
v1 - left-hand vector
s2 - right-hand scaling factor
v2 - right-hand vector
Throws:
ImproperSizeException - if v1 and v2 have different sizes, or if this vector needs resizing but is of fixed size

norm

public double norm()
Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.

Specified by:
norm in interface Vector
Overrides:
norm in class VectorBase
Returns:
vector 2 norm

normSquared

public double normSquared()
Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.

Specified by:
normSquared in interface Vector
Overrides:
normSquared in class VectorBase
Returns:
square of the 2 norm

maxElement

public double maxElement()
Returns the maximum element value of this vector.

Specified by:
maxElement in interface Vector
Overrides:
maxElement in class VectorBase
Returns:
maximal element

maxIndex

public int maxIndex()
Returns the index of the maximum element of this vector.

Returns:
maximal element index

minElement

public double minElement()
Returns the minimum element value of this vector.

Specified by:
minElement in interface Vector
Overrides:
minElement in class VectorBase
Returns:
minimal element

minIndex

public int minIndex()
Returns the index of the minimum element of this vector.

Returns:
minimal element index

infinityNorm

public double infinityNorm()
Returns the infinity norm of this vector. This is the maximum absolute value over all elements.

Specified by:
infinityNorm in interface Vector
Overrides:
infinityNorm in class VectorBase
Returns:
vector infinity norm

oneNorm

public double oneNorm()
Returns the 1 norm of this vector. This is the sum of the absolute values of the elements.

Specified by:
oneNorm in interface Vector
Overrides:
oneNorm in class VectorBase
Returns:
vector 1 norm

mean

public double mean()
Returns the mean value of the elements of this vector.

Returns:
vector mean

dot

public double dot(VectorNd v1)
           throws ImproperSizeException
Returns the dot product of this vector and v1.

Parameters:
v1 - right-hand vector
Returns:
dot product
Throws:
ImproperSizeException - if this vector and v1 have different sizes

angle

public double angle(VectorNd v1)
             throws ImproperSizeException
Returns the angle between this vector and v1. The angle is defined as acos(c), where c is the dot product of unit vectors parallel to this vector and v1.

Parameters:
v1 - right-hand vector
Returns:
angle between vectors, in radians
Throws:
ImproperSizeException - if this vector and v1 have different sizes

normalize

public void normalize()
Normalizes this vector in place.


normalize

public void normalize(VectorNd v1)
Computes a unit vector in the direction of v1 and places the result in this vector. This vector is resized if necessary.

Parameters:
v1 - vector to normalize
Throws:
ImproperSizeException - if this vector needs resizing but is of fixed size

epsilonEquals

public boolean epsilonEquals(VectorNd v1,
                             double eps)
                      throws ImproperSizeException
Returns true if the elements of this vector equal those of vector v1within a prescribed tolerance epsilon.

Parameters:
v1 - vector to compare with
eps - comparison tolerance
Returns:
false if the vectors are not equal within the specified tolerance, or have different sizes
Throws:
ImproperSizeException

equals

public boolean equals(VectorNd v1)
               throws ImproperSizeException
Returns true if the elements of this vector exactly equal those of vector v1.

Parameters:
v1 - vector to compare with
Returns:
false if the vectors are not equal or have different sizes
Throws:
ImproperSizeException

sum

public double sum()
Returns the sum of all the elements in this vector.

Returns:
sum of all the elements

setZero

public void setZero()
Sets the elements of this vector to zero.


absolute

public void absolute()
Sets the elements of this vector to their absolute values.


absolute

public void absolute(VectorNd v1)
Sets the elements of this vector to the absolute value of v1. This vector is resized if necessary.

Parameters:
v1 - vector to take the absolute value of
Throws:
ImproperSizeException - if this vector needs resizing but is of fixed size

sort

public void sort()
Sorts the contents of this vector by element value, from largest to smallest value.


sort

public void sort(VectorNd v1)
Sorts the contents of vector v1 by element value, from largest to smallest value, and places the result into this vector.

Parameters:
v1 - vector to sort

mul

public void mul(Matrix M,
                VectorNd b)
Multiplies matrix M by the vector b and places the result in this vector. This vector is resized if necessary.

Parameters:
M - left-hand matrix
b - right-hand vector
Throws:
ImproperSizeException - if the size of b does not equal the number of columns of M, or if this vector needs resizing but is of fixed size

mulTranspose

public void mulTranspose(Matrix M,
                         VectorNd b)
Multiplies the transpose of matrix M by the vector b and places the result in this vector. Note that this is equivalent to pre-multiplying M by b. This vector is resized if necessary.

Parameters:
M - left-hand matrix
b - right-hand vector
Throws:
ImproperSizeException - if the size of b does not equal the number of rows of M, or if this vector needs resizing but is of fixed size

setRandom

public void setRandom()
Sets the elements of this vector to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).


setRandom

public void setRandom(double lower,
                      double upper)
Sets the elements of this vector to uniformly distributed random values in a specified range.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)

setRandom

public void setRandom(double lower,
                      double upper,
                      java.util.Random generator)
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator

addNoise

public void addNoise(double eps)
Adds a random perturbation to this vector, in the range [-lim,lim], where
 lim = eps * infNorm
 
with eps supplied as an argument and infNorm is the infinityNorm of this vector.

Parameters:
eps - generates the noise range

addNoise

public void addNoise(double eps,
                     java.util.Random generator)
Adds a random perturbation to this vector, in the range [-lim,lim], where
 lim = eps * infNorm
 
with eps supplied as an argument and infNorm is the infinityNorm of this vector.

Parameters:
eps - generates the noise range
generator - random number generator to use

max

public void max(VectorNd v)
         throws ImproperSizeException
Computes the element-wise maximum of this vector and vector v and places the result in this vector.

Parameters:
v - vector to compare with
Throws:
ImproperSizeException - if this vector and v have different sizes

min

public void min(VectorNd v)
         throws ImproperSizeException
Computes the element-wise minimum of this vector and vector v and places the result in this vector.

Parameters:
v - vector to compare with
Throws:
ImproperSizeException - if this vector and v have different sizes

isRowVector

public boolean isRowVector()
Overrides:
isRowVector in class VectorBase

setRowVector

public boolean setRowVector(boolean isRow)
Overrides:
setRowVector in class VectorBase

clone

public VectorNd clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class VectorBase

permute

public void permute(int[] permutation)
Rearrange the elements of this vector according to the specified permutation, such that each element i is replaced by element permutation[i].

Parameters:
permutation - describes the element exchanges
Throws:
ImproperSizeException - if the length of permutation is less than the size of this vector.

distance

public double distance(VectorNd v)
Returns the distance between this vector and another. The distance is just the Euclidean norm of the different between the two vectors.

Parameters:
v - vector to find distance with respect to
Returns:
distance from v

hermiteInterpolate

public static void hermiteInterpolate(VectorNd pr,
                                      VectorNd p0,
                                      VectorNd v0,
                                      VectorNd p1,
                                      VectorNd v1,
                                      double s,
                                      double h)
Interpolates the value at a location along a cubic Hermite spline. The spline itself is defined by position and velocities at interval end-points. The location is defined by the parameter s in the range [0,1], and the actual time duration of the interval is given by h.

Parameters:
pr - returns interpolated position
p0 - position at the interval beginning
v0 - velocity at the interval beginning
p1 - position at the interval end
v1 - velocity at the interval end
s - interpolation location on the interval (in the range [0,1])
h - interval time duration