|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
public interface Vector
A Euclidean vector is a geometric object that has both a magnitude/length and direction.
The mathematical structure of a collection of vectors is a Hilbert space, c.f., HilbertSpace.
We do not dictate how a vector should be implemented. Different implementations of the mathematical concept 'vector' implements this interface.
This interface is made minimal so that we do not list all possible vector operations. Instead, vector operations are grouped into packages and classes by their properties. This is to avoid interface "pollution", lengthy and cumbersome design.
The only way to change a vector is by set(int, double).
Other operations that "change" the vector actually creates a new and independent copy.
| Method Summary | |
|---|---|
Vector |
add(double scalar)
v + s
Add a scalar to all entries in the vector v. |
Vector |
add(Vector that)
this + that |
double |
angle(Vector that)
Measure the angle between this and that. |
Vector |
deepCopy()
The implementation can return an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
Vector |
divide(Vector that)
this / that
Divide this by that, entry-by-entry. |
double |
get(int index)
Get the value at position index. |
double |
innerProduct(Vector that)
Inner product in the Euclidean space is the dot product. |
Vector |
minus(double scalar)
v - s
Subtract a scalar from all entries in the vector v. |
Vector |
minus(Vector that)
this - that |
Vector |
multiply(Vector that)
this * 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(int p)
Compute the norm of a vector. |
Vector |
opposite()
Get the opposite of this vector. |
Vector |
pow(double scalar)
v ^ s
Take the exponentiation of all entries in the vector v by a scalar. |
Vector |
scaled(double scalar)
scalar * this
Here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm()) |
Vector |
scaled(Real scalar)
scalar * that
If scalar is 1, it simply returns itself. |
void |
set(int index,
double value)
Change the value of an entry in this vector. |
int |
size()
Get the length of this vector. |
double[] |
toArray()
Get a copy of all vector entries in the form of a 1D double[] array. |
Vector |
ZERO()
Get a 0-vector that has the same length as this vector. |
| Method Detail |
|---|
int size()
double get(int index)
index.
index - position of a vector entry
v[index]
void set(int index,
double value)
The indices are, for example,: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ......
Note that we count from 1, NOT 0.
This is the only method that may change the entries of a vector.
index - the entry to changevalue - the value to change toVector add(Vector that)
this + that
add in interface AbelianGroup<Vector>that - a vector
this and thatVector minus(Vector that)
this - that
minus in interface AbelianGroup<Vector>that - a vector
this and thatVector multiply(Vector that)
this * that
Multiply this by that, entry-by-entry.
that - a vector
this * that, entry-by-entryVector divide(Vector that)
this / that
Divide this by that, entry-by-entry.
that - a vector
this / that, entry-by-entryVector add(double scalar)
v + s
Add a scalar to all entries in the vector v.
scalar - s
v + sVector minus(double scalar)
v - s
Subtract a scalar from all entries in the vector v.
scalar - s
v - sdouble innerProduct(Vector that)
Dot product is an operation which takes two vectors over the real numbers R
and returns a real-valued scalar quantity.
innerProduct in interface HilbertSpace<Vector,Real>that - a vector
this and that,
i.e., this ∙ thatVector pow(double scalar)
v ^ s
Take the exponentiation of all entries in the vector v by a scalar.
scalar - s
v ^ sVector scaled(double scalar)
scalar * this
Here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm())
scalar - a double scalar
scalarVector scaled(Real scalar)
scalar * that
If scalar is 1, it simply returns itself.
So, here is a way to get a unit version of the vector:
vector.scaled(1. / vector.norm())
scaled in interface VectorSpace<Vector,Real>scalar - a Real number scalar
scalardouble norm()
||v||.
norm in interface BanachSpace<Vector,Real>double norm(int p)
p is finite,
|v|p = ∑ [(abs(vi)^p)]^(1/p)
When p is +∞ (Integer.MAX_VALUE),
|v|p = max(abs(vi))
When p is -∞ (Integer.MIN_VALUE),
|v|p = min(abs(vi))
p - an integer, Integer.MAX_VALUE, or Integer.MIN_VALUE
double angle(Vector that)
this and that.
That is,
this ∙ that = ||this|| * ||that|| cos(angle)
angle in interface HilbertSpace<Vector,Real>that - a vector
this and thatVector opposite()
opposite in interface AbelianGroup<Vector>-vVector ZERO()
ZERO in interface AbelianGroup<Vector>double[] toArray()
double[] array.
double[]Vector deepCopy()
DeepCopyablethis by the copy
constructor of the class, or just this if the instance itself is
immutable.
deepCopy in interface DeepCopyable
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||