# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.algebra.linear.vector.doubles.dense

## Class DenseVector

• java.lang.Object
• com.numericalmethod.suanshu.algebra.linear.vector.doubles.dense.DenseVector
• ### Constructor Summary

Constructors
Constructor and Description
DenseVector(Collection<? extends Number> data)
Constructs a vector, initialized by a collection, with order defined by its iterator.
DenseVector(DenseVector vector)
Copy constructor.
DenseVector(double... data)
Constructs a vector, initialized by a double[].
DenseVector(Double[] data)
Constructs a vector, initialized by a Double[].
DenseVector(int length)
Constructs a vector.
DenseVector(int[] data)
Constructs a vector, initialized by a int[].
DenseVector(int length, double value)
Constructs a vector, initialized by repeating a value.
DenseVector(List<Double> data)
Constructs a vector, initialized by a List<Double>.
DenseVector(Matrix A)
Constructs a vector from a column or row matrix.
DenseVector(Vector v)
Casts any vector to a DenseVector.
• ### Method Summary

All Methods
Modifier and Type Method and Description
DenseVector add(DenseVector that)
DenseVector add(double scalar)
Add a constant to all entries in this vector.
Vector add(Vector that)
$$this + that$$
double angle(Vector that)
Measure the angle, $$\theta$$, between this and that.
DenseVector deepCopy()
The implementation returns an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
DenseVector divide(DenseVector that)
Vector divide(Vector that)
Divide this by that, entry-by-entry.
boolean equals(Object obj)
double get(int i)
Get the value at position i.
int hashCode()
double innerProduct(DenseVector that)
double innerProduct(Vector that)
Inner product in the Euclidean space is the dot product.
DenseVector minus(DenseVector that)
DenseVector minus(double scalar)
Subtract a constant from all entries in this vector.
Vector minus(Vector that)
$$this - that$$
DenseVector multiply(DenseVector that)
Vector multiply(Vector that)
Multiply this by that, entry-by-entry.
double norm()
Compute the length or magnitude or Euclidean norm of a vector, namely, $$\|v\|$$.
double norm(double p)
Gets the $$L^p$$-norm $$\|v\|_p$$ of this vector.
DenseVector opposite()
Get the opposite of this vector.
DenseVector pow(double scalar)
Take the exponentiation of all entries in this vector, entry-by-entry.
DenseVector scaled(double c)
Scale this vector by a constant, entry-by-entry.
DenseVector scaled(Real c)
Scale this vector by a constant, entry-by-entry.
void set(int from, DenseVector replacement)
Replaces a sub-vector v[from : replacement.length] by a replacement starting at position from.
void set(int i, double value)
Change the value of an entry in this vector.
int size()
Get the length of this vector.
double[] toArray()
Cast this vector into a 1D double[].
String toString()
DenseVector ZERO()
Get a 0-vector that has the same length as this vector.
• ### Methods inherited from class java.lang.Object

clone, finalize, getClass, notify, notifyAll, wait, wait, wait
• ### Constructor Detail

• #### DenseVector

public DenseVector(int length)
Constructs a vector.
Parameters:
length - the length of this vector
• #### DenseVector

public DenseVector(int length,
double value)
Constructs a vector, initialized by repeating a value.
Parameters:
length - the length of this vector
value - the initial value
• #### DenseVector

public DenseVector(double... data)
Constructs a vector, initialized by a double[].
Parameters:
data - an 1D array
• #### DenseVector

public DenseVector(Double[] data)
Constructs a vector, initialized by a Double[].
Parameters:
data - an 1D array
• #### DenseVector

public DenseVector(List<Double> data)
Constructs a vector, initialized by a List<Double>.
Parameters:
data - an 1D array
• #### DenseVector

public DenseVector(Collection<? extends Number> data)
Constructs a vector, initialized by a collection, with order defined by its iterator. Only the real/double part is used, by calling Number.doubleValue().
Parameters:
data - a collection of Number
• #### DenseVector

public DenseVector(int[] data)
Constructs a vector, initialized by a int[].
Parameters:
data - an 1D array
• #### DenseVector

public DenseVector(Matrix A)
Constructs a vector from a column or row matrix.
Parameters:
A - a column or row matrix
• #### DenseVector

public DenseVector(Vector v)
Casts any vector to a DenseVector.
Parameters:
v - a vector
• #### DenseVector

public DenseVector(DenseVector vector)
Copy constructor.
Parameters:
vector - a vector
• ### Method Detail

• #### size

public int size()
Description copied from interface: Vector
Get the length of this vector.
Specified by:
size in interface Vector
Returns:
the vector length
• #### set

public void set(int i,
double value)
Description copied from interface: Vector
Change the value of an entry in this vector. This is the only method that may change the entries of a vector.
Specified by:
set in interface Vector
Parameters:
i - the index of the entry to change. The indices are counting from 1, NOT 0.
value - the value to change to
• #### set

public void set(int from,
DenseVector replacement)
Replaces a sub-vector v[from : replacement.length] by a replacement starting at position from.
Parameters:
from - the starting position of the replacement
replacement - a vector for substitution
Throws:
IllegalArgumentException - if the replacement length exceeds the end of this vector
• #### get

public double get(int i)
Description copied from interface: Vector
Get the value at position i.
Specified by:
get in interface Vector
Parameters:
i - the position of a vector entry
Returns:
v[i]

public Vector add(Vector that)
Description copied from interface: Vector
$$this + that$$
Specified by:
add in interface Vector
Specified by:
add in interface AbelianGroup<Vector>
Parameters:
that - a vector
Returns:
$$this + that$$

public DenseVector add(DenseVector that)
• #### minus

public Vector minus(Vector that)
Description copied from interface: Vector
$$this - that$$
Specified by:
minus in interface Vector
Specified by:
minus in interface AbelianGroup<Vector>
Parameters:
that - a vector
Returns:
$$this - that$$
• #### minus

public DenseVector minus(DenseVector that)
• #### scaled

public DenseVector scaled(double c)
Description copied from interface: Vector
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:
 vector.scaled(1. / vector.norm()) 
Specified by:
scaled in interface Vector
Parameters:
c - a constant
Returns:
$$c \times this$$
• #### scaled

public DenseVector scaled(Real c)
Description copied from interface: Vector
Scale this vector by a constant, entry-by-entry. Here is a way to get a unit version of the vector:
 vector.scaled(1. / vector.norm()) 
Specified by:
scaled in interface Vector
Specified by:
scaled in interface VectorSpace<Vector,Real>
Parameters:
c - a constant
Returns:
$$c \times this$$
Wikipedia: Scalar multiplication
• #### opposite

public DenseVector opposite()
Description copied from interface: Vector
Get the opposite of this vector.
Specified by:
opposite in interface Vector
Specified by:
opposite in interface AbelianGroup<Vector>
Returns:
-v
• #### multiply

public Vector multiply(Vector that)
Description copied from interface: Vector
Multiply this by that, entry-by-entry.
Specified by:
multiply in interface Vector
Parameters:
that - a vector
Returns:
$$this \cdot that$$
• #### multiply

public DenseVector multiply(DenseVector that)
• #### divide

public Vector divide(Vector that)
Description copied from interface: Vector
Divide this by that, entry-by-entry.
Specified by:
divide in interface Vector
Parameters:
that - a vector
Returns:
$$this / that$$
• #### divide

public DenseVector divide(DenseVector that)

public DenseVector add(double scalar)
Description copied from interface: Vector
Add a constant to all entries in this vector.
Specified by:
add in interface Vector
Parameters:
scalar - a constant
Returns:
$$v + c$$
• #### minus

public DenseVector minus(double scalar)
Description copied from interface: Vector
Subtract a constant from all entries in this vector.
Specified by:
minus in interface Vector
Parameters:
scalar - a constant
Returns:
$$v - c$$
• #### pow

public DenseVector pow(double scalar)
Description copied from interface: Vector
Take the exponentiation of all entries in this vector, entry-by-entry.
Specified by:
pow in interface Vector
Parameters:
scalar - a constant
Returns:
$$v ^ s$$
• #### norm

public double norm()
Description copied from interface: Vector
Compute the length or magnitude or Euclidean norm of a vector, namely, $$\|v\|$$.
Specified by:
norm in interface Vector
Specified by:
norm in interface BanachSpace<Vector,Real>
Returns:
the Euclidean norm
Wikipedia: Norm (mathematics)
• #### angle

public double angle(Vector that)
Description copied from interface: Vector
Measure the angle, $$\theta$$, between this and that. That is, $this \cdot that = \|this\| \times \|that\| \times \cos \theta$
Specified by:
angle in interface Vector
Specified by:
angle in interface HilbertSpace<Vector,Real>
Parameters:
that - a vector
Returns:
the angle, $$\theta$$, between this and that
• #### innerProduct

public double innerProduct(Vector that)
Description copied from interface: Vector
Inner product in the Euclidean space is the dot product.
Specified by:
innerProduct in interface Vector
Specified by:
innerProduct in interface HilbertSpace<Vector,Real>
Parameters:
that - a vector
Returns:
$$this \cdot that$$
Wikipedia: Dot product
• #### innerProduct

public double innerProduct(DenseVector that)
• #### ZERO

public DenseVector ZERO()
Description copied from interface: Vector
Get a 0-vector that has the same length as this vector.
Specified by:
ZERO in interface Vector
Specified by:
ZERO in interface AbelianGroup<Vector>
Returns:
the 0-vector
• #### toArray

public double[] toArray()
Description copied from interface: Vector
Cast this vector into a 1D double[].
Specified by:
toArray in interface Vector
Returns:
a copy of all vector entries as a double[]
• #### deepCopy

public DenseVector deepCopy()
Description copied from interface: DeepCopyable
The implementation returns an instance created from this by the copy constructor of the class, or just this if the instance itself is immutable.
Specified by:
deepCopy in interface Vector
Specified by:
deepCopy in interface DeepCopyable
Returns:
an independent (deep) copy of the instance
• #### toString

public String toString()
Overrides:
toString in class Object
• #### equals

public boolean equals(Object obj)
Overrides:
equals in class Object
• #### hashCode

public int hashCode()
Overrides:
hashCode in class Object