org.apache.commons.math.linear
Class RealVectorImpl

java.lang.Object
  extended by org.apache.commons.math.linear.RealVectorImpl
All Implemented Interfaces:
Serializable, RealVector

public class RealVectorImpl
extends Object
implements RealVector, Serializable

This class implements the RealVector interface with a double array.

Since:
2.0
Version:
$Revision: 701883 $ $Date: 2008-10-05 22:37:15 +0200 (dim, 05 oct 2008) $
See Also:
Serialized Form

Field Summary
protected  double[] data
          Entries of the vector.
 
Constructor Summary
RealVectorImpl()
          Build a 0-length vector.
RealVectorImpl(double[] d)
          Construct a vector from an array, copying the input array.
RealVectorImpl(Double[] d)
          Construct a vector from an array.
RealVectorImpl(double[] d, boolean copyArray)
          Create a new RealVectorImpl using the input array as the underlying data array.
RealVectorImpl(double[] v1, double[] v2)
          Construct a vector by appending one vector to another vector.
RealVectorImpl(double[] d, int pos, int size)
          Construct a vector from part of a array.
RealVectorImpl(Double[] d, int pos, int size)
          Construct a vector from part of a Double array
RealVectorImpl(double[] v1, RealVectorImpl v2)
          Construct a vector by appending one vector to another vector.
RealVectorImpl(int size)
          Construct a (size)-length vector of zeros.
RealVectorImpl(int size, double preset)
          Construct an (size)-length vector with preset values.
RealVectorImpl(RealVector v)
          Construct a vector from another vector, using a deep copy.
RealVectorImpl(RealVectorImpl v)
          Construct a vector from another vector, using a deep copy.
RealVectorImpl(RealVectorImpl v, boolean deep)
          Construct a vector from another vector.
RealVectorImpl(RealVectorImpl v1, double[] v2)
          Construct a vector by appending one vector to another vector.
RealVectorImpl(RealVectorImpl v1, RealVectorImpl v2)
          Construct a vector by appending one vector to another vector.
 
Method Summary
 RealVector add(double[] v)
          Compute the sum of this and v.
 RealVector add(RealVector v)
          Compute the sum of this and v.
 RealVectorImpl add(RealVectorImpl v)
          Compute the sum of this and v.
 RealVector append(double in)
          Construct a vector by appending a double to this vector.
 RealVector append(double[] in)
          Construct a vector by appending a double array to this vector.
 RealVector append(RealVector v)
          Construct a vector by appending a vector to this vector.
 RealVectorImpl append(RealVectorImpl v)
          Construct a vector by appending a vector to this vector.
 void checkVectorDimensions(int n)
          Check if instance dimension is equal to some expected value.
 void checkVectorDimensions(RealVector v)
          Check if instance and specified vectors have the same dimension.
 RealVector copy()
          Returns a (deep) copy of this.
 double dotProduct(double[] v)
          Compute the dot product.
 double dotProduct(RealVector v)
          Compute the dot product.
 double dotProduct(RealVectorImpl v)
          Compute the dot product.
 RealVector ebeDivide(double[] v)
          Element-by-element division.
 RealVector ebeDivide(RealVector v)
          Element-by-element division.
 RealVectorImpl ebeDivide(RealVectorImpl v)
          Element-by-element division.
 RealVector ebeMultiply(double[] v)
          Element-by-element multiplication.
 RealVector ebeMultiply(RealVector v)
          Element-by-element multiplication.
 RealVectorImpl ebeMultiply(RealVectorImpl v)
          Element-by-element multiplication.
 boolean equals(Object other)
          Test for the equality of two real vectors.
 RealVector get(int index, int n)
          Get a subvector from consecutive elements.
 double[] getData()
          Returns vector entries as a double array.
 double[] getDataRef()
          Returns a reference to the underlying data array.
 int getDimension()
          Returns the size of the vector.
 double getDistance(double[] v)
          Distance between two vectors.
 double getDistance(RealVector v)
          Distance between two vectors.
 double getDistance(RealVectorImpl v)
          Distance between two vectors.
 double getEntry(int index)
          Returns the entry in the specified index.
 double getL1Distance(double[] v)
          Distance between two vectors.
 double getL1Distance(RealVector v)
          Distance between two vectors.
 double getL1Distance(RealVectorImpl v)
          Distance between two vectors.
 double getL1Norm()
          Returns the L1 norm of the vector.
 double getLInfDistance(double[] v)
          Distance between two vectors.
 double getLInfDistance(RealVector v)
          Distance between two vectors.
 double getLInfDistance(RealVectorImpl v)
          Distance between two vectors.
 double getLInfNorm()
          Returns the L&infty; norm of the vector.
 double getNorm()
          Returns the L2 norm of the vector.
 int hashCode()
          Get a hashCode for the real vector.
 boolean isInfinite()
          Returns true if any coordinate of this vector is infinite and none are NaN; false otherwise
 boolean isNaN()
          Returns true if any coordinate of this vector is NaN; false otherwise
 RealVector mapAbs()
          Map the Math.abs(double) function to each entry.
 RealVector mapAbsToSelf()
          Map the Math.abs(double) function to each entry.
 RealVector mapAcos()
          Map the Math.acos(double) function to each entry.
 RealVector mapAcosToSelf()
          Map the Math.acos(double) function to each entry.
 RealVector mapAdd(double d)
          Map an addition operation to each entry.
 RealVector mapAddToSelf(double d)
          Map an addition operation to each entry.
 RealVector mapAsin()
          Map the Math.asin(double) function to each entry.
 RealVector mapAsinToSelf()
          Map the Math.asin(double) function to each entry.
 RealVector mapAtan()
          Map the Math.atan(double) function to each entry.
 RealVector mapAtanToSelf()
          Map the Math.atan(double) function to each entry.
 RealVector mapCbrt()
          Map the Math.cbrt(double) function to each entry.
 RealVector mapCbrtToSelf()
          Map the Math.cbrt(double) function to each entry.
 RealVector mapCeil()
          Map the Math.ceil(double) function to each entry.
 RealVector mapCeilToSelf()
          Map the Math.ceil(double) function to each entry.
 RealVector mapCos()
          Map the Math.cos(double) function to each entry.
 RealVector mapCosh()
          Map the Math.cosh(double) function to each entry.
 RealVector mapCoshToSelf()
          Map the Math.cosh(double) function to each entry.
 RealVector mapCosToSelf()
          Map the Math.cos(double) function to each entry.
 RealVector mapDivide(double d)
          Map a division operation to each entry.
 RealVector mapDivideToSelf(double d)
          Map a division operation to each entry.
 RealVector mapExp()
          Map the Math.exp(double) function to each entry.
 RealVector mapExpm1()
          Map the Math.expm1(double) function to each entry.
 RealVector mapExpm1ToSelf()
          Map the Math.expm1(double) function to each entry.
 RealVector mapExpToSelf()
          Map the Math.exp(double) function to each entry.
 RealVector mapFloor()
          Map the Math.floor(double) function to each entry.
 RealVector mapFloorToSelf()
          Map the Math.floor(double) function to each entry.
 RealVector mapInv()
          Map the 1/x function to each entry.
 RealVector mapInvToSelf()
          Map the 1/x function to each entry.
 RealVector mapLog()
          Map the Math.log(double) function to each entry.
 RealVector mapLog10()
          Map the Math.log10(double) function to each entry.
 RealVector mapLog10ToSelf()
          Map the Math.log10(double) function to each entry.
 RealVector mapLog1p()
          Map the Math.log1p(double) function to each entry.
 RealVector mapLog1pToSelf()
          Map the Math.log1p(double) function to each entry.
 RealVector mapLogToSelf()
          Map the Math.log(double) function to each entry.
 RealVector mapMultiply(double d)
          Map a multiplication operation to each entry.
 RealVector mapMultiplyToSelf(double d)
          Map a multiplication operation to each entry.
 RealVector mapPow(double d)
          Map a power operation to each entry.
 RealVector mapPowToSelf(double d)
          Map a power operation to each entry.
 RealVector mapRint()
          Map the Math.rint(double) function to each entry.
 RealVector mapRintToSelf()
          Map the Math.rint(double) function to each entry.
 RealVector mapSignum()
          Map the Math.signum(double) function to each entry.
 RealVector mapSignumToSelf()
          Map the Math.signum(double) function to each entry.
 RealVector mapSin()
          Map the Math.sin(double) function to each entry.
 RealVector mapSinh()
          Map the Math.sinh(double) function to each entry.
 RealVector mapSinhToSelf()
          Map the Math.sinh(double) function to each entry.
 RealVector mapSinToSelf()
          Map the Math.sin(double) function to each entry.
 RealVector mapSqrt()
          Map the Math.sqrt(double) function to each entry.
 RealVector mapSqrtToSelf()
          Map the Math.sqrt(double) function to each entry.
 RealVector mapSubtract(double d)
          Map a subtraction operation to each entry.
 RealVector mapSubtractToSelf(double d)
          Map a subtraction operation to each entry.
 RealVector mapTan()
          Map the Math.tan(double) function to each entry.
 RealVector mapTanh()
          Map the Math.tanh(double) function to each entry.
 RealVector mapTanhToSelf()
          Map the Math.tanh(double) function to each entry.
 RealVector mapTanToSelf()
          Map the Math.tan(double) function to each entry.
 RealVector mapUlp()
          Map the Math.ulp(double) function to each entry.
 RealVector mapUlpToSelf()
          Map the Math.ulp(double) function to each entry.
 RealMatrix outerProduct(double[] v)
          Compute the outer product.
 RealMatrix outerProduct(RealVector v)
          Compute the outer product.
 RealMatrixImpl outerProduct(RealVectorImpl v)
          Compute the outer product.
 RealVector projection(double[] v)
          Find the orthogonal projection of this vector onto another vector.
 RealVector projection(RealVector v)
          Find the orthogonal projection of this vector onto another vector.
 RealVectorImpl projection(RealVectorImpl v)
          Find the orthogonal projection of this vector onto another vector.
 void set(double value)
          Set all elements to a single value.
 void set(int index, double value)
          Set a single element.
 void set(int index, double[] v)
          Set a set of consecutive elements.
 void set(int index, RealVector v)
          Set a set of consecutive elements.
 void set(int index, RealVectorImpl v)
          Set a set of consecutive elements.
 RealVector subtract(double[] v)
          Compute this minus v.
 RealVector subtract(RealVector v)
          Compute this minus v.
 RealVectorImpl subtract(RealVectorImpl v)
          Compute this minus v.
 double[] toArray()
          Convert the vector to a double array.
 String toString()
          
 void unitize()
          Converts this vector into a unit vector.
 RealVector unitVector()
          Creates a unit vector pointing in the direction of this vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected double[] data
Entries of the vector.

Constructor Detail

RealVectorImpl

public RealVectorImpl()
Build a 0-length vector.

Zero-length vectors may be used to initialized construction of vectors by data gathering. We start with zero-length and use either the RealVectorImpl(RealVectorImpl, RealVectorImpl) constructor or one of the append method (append(double), append(double[]), append(RealVectorImpl)) to gather data into this vector.


RealVectorImpl

public RealVectorImpl(int size)
Construct a (size)-length vector of zeros.

Parameters:
size - size of the vector

RealVectorImpl

public RealVectorImpl(int size,
                      double preset)
Construct an (size)-length vector with preset values.

Parameters:
size - size of the vector
preset - fill the vector with this scalar value

RealVectorImpl

public RealVectorImpl(double[] d)
Construct a vector from an array, copying the input array.

Parameters:
d - array of doubles.

RealVectorImpl

public RealVectorImpl(double[] d,
                      boolean copyArray)
               throws NullPointerException,
                      IllegalArgumentException
Create a new RealVectorImpl using the input array as the underlying data array.

If an array is built specially in order to be embedded in a RealVectorImpl and not used directly, the copyArray may be set to false

Parameters:
d - data for new vector
copyArray - if true, the input array will be copied, otherwise it will be referenced
Throws:
IllegalArgumentException - if d is empty
NullPointerException - if d is null
See Also:
RealVectorImpl(double[])

RealVectorImpl

public RealVectorImpl(double[] d,
                      int pos,
                      int size)
Construct a vector from part of a array.

Parameters:
d - array of doubles.
pos - position of first entry
size - number of entries to copy

RealVectorImpl

public RealVectorImpl(Double[] d)
Construct a vector from an array.

Parameters:
d - array of Doubles.

RealVectorImpl

public RealVectorImpl(Double[] d,
                      int pos,
                      int size)
Construct a vector from part of a Double array

Parameters:
d - array of Doubles.
pos - position of first entry
size - number of entries to copy

RealVectorImpl

public RealVectorImpl(RealVector v)
Construct a vector from another vector, using a deep copy.

Parameters:
v - vector to copy

RealVectorImpl

public RealVectorImpl(RealVectorImpl v)
Construct a vector from another vector, using a deep copy.

Parameters:
v - vector to copy

RealVectorImpl

public RealVectorImpl(RealVectorImpl v,
                      boolean deep)
Construct a vector from another vector.

Parameters:
v - vector to copy
deep - if true perform a deep copy otherwise perform a shallow copy

RealVectorImpl

public RealVectorImpl(RealVectorImpl v1,
                      RealVectorImpl v2)
Construct a vector by appending one vector to another vector.

Parameters:
v1 - first vector (will be put in front of the new vector)
v2 - second vector (will be put at back of the new vector)

RealVectorImpl

public RealVectorImpl(RealVectorImpl v1,
                      double[] v2)
Construct a vector by appending one vector to another vector.

Parameters:
v1 - first vector (will be put in front of the new vector)
v2 - second vector (will be put at back of the new vector)

RealVectorImpl

public RealVectorImpl(double[] v1,
                      RealVectorImpl v2)
Construct a vector by appending one vector to another vector.

Parameters:
v1 - first vector (will be put in front of the new vector)
v2 - second vector (will be put at back of the new vector)

RealVectorImpl

public RealVectorImpl(double[] v1,
                      double[] v2)
Construct a vector by appending one vector to another vector.

Parameters:
v1 - first vector (will be put in front of the new vector)
v2 - second vector (will be put at back of the new vector)
Method Detail

copy

public RealVector copy()
Returns a (deep) copy of this.

Specified by:
copy in interface RealVector
Returns:
vector copy

add

public RealVector add(RealVector v)
               throws IllegalArgumentException
Compute the sum of this and v.

Specified by:
add in interface RealVector
Parameters:
v - vector to be added
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

add

public RealVector add(double[] v)
               throws IllegalArgumentException
Compute the sum of this and v.

Specified by:
add in interface RealVector
Parameters:
v - vector to be added
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

add

public RealVectorImpl add(RealVectorImpl v)
                   throws IllegalArgumentException
Compute the sum of this and v.

Parameters:
v - vector to be added
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

subtract

public RealVector subtract(RealVector v)
                    throws IllegalArgumentException
Compute this minus v.

Specified by:
subtract in interface RealVector
Parameters:
v - vector to be subtracted
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

subtract

public RealVector subtract(double[] v)
                    throws IllegalArgumentException
Compute this minus v.

Specified by:
subtract in interface RealVector
Parameters:
v - vector to be subtracted
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

subtract

public RealVectorImpl subtract(RealVectorImpl v)
                        throws IllegalArgumentException
Compute this minus v.

Parameters:
v - vector to be subtracted
Returns:
this + v
Throws:
IllegalArgumentException - if v is not the same size as this

mapAdd

public RealVector mapAdd(double d)
Map an addition operation to each entry.

Specified by:
mapAdd in interface RealVector
Parameters:
d - value to be added to each entry
Returns:
this + d

mapAddToSelf

public RealVector mapAddToSelf(double d)
Map an addition operation to each entry.

The instance is changed by this method.

Specified by:
mapAddToSelf in interface RealVector
Parameters:
d - value to be added to each entry
Returns:
for convenience, return this

mapSubtract

public RealVector mapSubtract(double d)
Map a subtraction operation to each entry.

Specified by:
mapSubtract in interface RealVector
Parameters:
d - value to be subtracted to each entry
Returns:
this - d

mapSubtractToSelf

public RealVector mapSubtractToSelf(double d)
Map a subtraction operation to each entry.

The instance is changed by this method.

Specified by:
mapSubtractToSelf in interface RealVector
Parameters:
d - value to be subtracted to each entry
Returns:
for convenience, return this

mapMultiply

public RealVector mapMultiply(double d)
Map a multiplication operation to each entry.

Specified by:
mapMultiply in interface RealVector
Parameters:
d - value to multiply all entries by
Returns:
this * d

mapMultiplyToSelf

public RealVector mapMultiplyToSelf(double d)
Map a multiplication operation to each entry.

The instance is changed by this method.

Specified by:
mapMultiplyToSelf in interface RealVector
Parameters:
d - value to multiply all entries by
Returns:
for convenience, return this

mapDivide

public RealVector mapDivide(double d)
Map a division operation to each entry.

Specified by:
mapDivide in interface RealVector
Parameters:
d - value to divide all entries by
Returns:
this / d

mapDivideToSelf

public RealVector mapDivideToSelf(double d)
Map a division operation to each entry.

The instance is changed by this method.

Specified by:
mapDivideToSelf in interface RealVector
Parameters:
d - value to divide all entries by
Returns:
for convenience, return this

mapPow

public RealVector mapPow(double d)
Map a power operation to each entry.

Specified by:
mapPow in interface RealVector
Parameters:
d - value to raise all entries to
Returns:
this ^ d

mapPowToSelf

public RealVector mapPowToSelf(double d)
Map a power operation to each entry.

The instance is changed by this method.

Specified by:
mapPowToSelf in interface RealVector
Parameters:
d - value to raise all entries to
Returns:
for convenience, return this

mapExp

public RealVector mapExp()
Map the Math.exp(double) function to each entry.

Specified by:
mapExp in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapExpToSelf

public RealVector mapExpToSelf()
Map the Math.exp(double) function to each entry.

The instance is changed by this method.

Specified by:
mapExpToSelf in interface RealVector
Returns:
for convenience, return this

mapExpm1

public RealVector mapExpm1()
Map the Math.expm1(double) function to each entry.

Specified by:
mapExpm1 in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapExpm1ToSelf

public RealVector mapExpm1ToSelf()
Map the Math.expm1(double) function to each entry.

The instance is changed by this method.

Specified by:
mapExpm1ToSelf in interface RealVector
Returns:
for convenience, return this

mapLog

public RealVector mapLog()
Map the Math.log(double) function to each entry.

Specified by:
mapLog in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLogToSelf

public RealVector mapLogToSelf()
Map the Math.log(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLogToSelf in interface RealVector
Returns:
for convenience, return this

mapLog10

public RealVector mapLog10()
Map the Math.log10(double) function to each entry.

Specified by:
mapLog10 in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLog10ToSelf

public RealVector mapLog10ToSelf()
Map the Math.log10(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLog10ToSelf in interface RealVector
Returns:
for convenience, return this

mapLog1p

public RealVector mapLog1p()
Map the Math.log1p(double) function to each entry.

Specified by:
mapLog1p in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapLog1pToSelf

public RealVector mapLog1pToSelf()
Map the Math.log1p(double) function to each entry.

The instance is changed by this method.

Specified by:
mapLog1pToSelf in interface RealVector
Returns:
for convenience, return this

mapCosh

public RealVector mapCosh()
Map the Math.cosh(double) function to each entry.

Specified by:
mapCosh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCoshToSelf

public RealVector mapCoshToSelf()
Map the Math.cosh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCoshToSelf in interface RealVector
Returns:
for convenience, return this

mapSinh

public RealVector mapSinh()
Map the Math.sinh(double) function to each entry.

Specified by:
mapSinh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSinhToSelf

public RealVector mapSinhToSelf()
Map the Math.sinh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapSinhToSelf in interface RealVector
Returns:
for convenience, return this

mapTanh

public RealVector mapTanh()
Map the Math.tanh(double) function to each entry.

Specified by:
mapTanh in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapTanhToSelf

public RealVector mapTanhToSelf()
Map the Math.tanh(double) function to each entry.

The instance is changed by this method.

Specified by:
mapTanhToSelf in interface RealVector
Returns:
for convenience, return this

mapCos

public RealVector mapCos()
Map the Math.cos(double) function to each entry.

Specified by:
mapCos in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapCosToSelf

public RealVector mapCosToSelf()
Map the Math.cos(double) function to each entry.

The instance is changed by this method.

Specified by:
mapCosToSelf in interface RealVector
Returns:
for convenience, return this

mapSin

public RealVector mapSin()
Map the Math.sin(double) function to each entry.

Specified by:
mapSin in interface RealVector
Returns:
a vector containing the result of applying the function to each entry

mapSinToSelf

public RealVector mapSinToSelf</