public final class Vector extends Object
| Constructor and Description |
|---|
Vector(double... elements)
Create a new vector using the provided elements.
|
| Modifier and Type | Method and Description |
|---|---|
double |
at(int i)
Return the element at index i, where indexing begins at 0.
|
double |
dotProduct(Vector other)
Compute the dot product of this vector with the given vector.
|
double[] |
elements()
The elements of the vector as an array of primitive doubles.
|
boolean |
equals(Object obj) |
static Vector |
from(double... elements)
Create a new vector from the given elements.
|
int |
hashCode() |
Vector |
minus(double scalar)
Subtract the given scalar from this vector and return the result in a new vector.
|
Vector |
minus(Vector other)
Subtract the given vector from this vector and return the result in a new vector.
|
double |
norm()
Compute the L2 length of this vector.
|
Matrix |
outerProduct(Vector other)
Compute the outer product of this vector and the given vector.
|
Vector |
plus(Vector other)
Add this vector to the given vector and return the result in a new vector.
|
Vector |
scaledBy(double alpha)
Scale this vector by the given scalar and return the result in a new vector.
|
int |
size()
The number of elements in this vector.
|
double |
sum()
Compute the sum of the elements of this vector.
|
double |
sumOfSquares()
Compute the sum of squared elements of this vector.
|
String |
toString() |
public Vector(double... elements)
elements - the elements of the new vector.public static Vector from(double... elements)
elements - the elements of the new vector.public double[] elements()
public double at(int i)
i - the index of the element.public int size()
public Vector plus(Vector other)
other - the vector to add to this vector.public Vector minus(Vector other)
other - the vector to subtract from this vector.public Vector minus(double scalar)
scalar - the scalar to subtract from this vector.public Vector scaledBy(double alpha)
alpha - the scalar to scale this vector by.public double dotProduct(Vector other)
other - the vector to take the dot product with.public Matrix outerProduct(Vector other)
other - the vector to compute the outer product of this vector with.public double norm()
public double sum()
public double sumOfSquares()