public class Vector extends Object
Vector
class represents a ddimensional Euclidean vector.
Vectors are immutable: their values cannot be changed after they are created.
It includes methods for addition, subtraction,
dot product, scalar product, unit vector, Euclidean norm, and the Euclidean
distance between two vectors.
For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

Vector(double... a)
Initializes a vector from either an array or a vararg list.

Vector(int d)
Initializes a ddimensional zero vector.

Modifier and Type  Method and Description 

double 
cartesian(int i)
Returns the ith cartesian coordinate.

int 
dimension()
Returns the dimension of this vector.

Vector 
direction()
Returns a unit vector in the direction of this vector.

double 
distanceTo(Vector that)
Returns the Euclidean distance between this vector and the specified vector.

double 
dot(Vector that)
Returns the do product of this vector with the specified vector.

int 
length()
Deprecated.
Replaced by
dimension() . 
double 
magnitude()
Returns the magnitude of this vector.

static void 
main(String[] args)
Unit tests the
Vector data type. 
Vector 
minus(Vector that)
Returns the difference between this vector and the specified vector.

Vector 
plus(Vector that)
Returns the sum of this vector and the specified vector.

Vector 
scale(double alpha)
Returns the scalarvector product of this vector and the specified scalar

Vector 
times(double alpha)
Deprecated.
Replaced by
scale(double) . 
String 
toString()
Returns a string representation of this vector.

public Vector(int d)
d
 the dimension of the vectorpublic Vector(double... a)
a
 the array or vararg list@Deprecated public int length()
dimension()
.public int dimension()
public double dot(Vector that)
that
 the other vectorIllegalArgumentException
 if the dimensions of the two vectors are not equalpublic double magnitude()
public double distanceTo(Vector that)
that
 the other vectorIllegalArgumentException
 if the dimensions of the two vectors are not equalpublic Vector plus(Vector that)
that
 the vector to add to this vector(this + that)
IllegalArgumentException
 if the dimensions of the two vectors are not equalpublic Vector minus(Vector that)
that
 the vector to subtract from this vector(this  that)
IllegalArgumentException
 if the dimensions of the two vectors are not equalpublic double cartesian(int i)
i
 the coordinate index@Deprecated public Vector times(double alpha)
scale(double)
.alpha
 the scalar(alpha * this)
public Vector scale(double alpha)
alpha
 the scalar(alpha * this)
public Vector direction()
ArithmeticException
 if this vector is the zero vectorpublic String toString()
public static void main(String[] args)
Vector
data type.args
 the commandline arguments