|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.matrix.VectorObject
maspack.matrix.VectorNd
Implements general vectors, along with their most commonly used operations.
These vectors can be resized, either explicitly through a call to setSize
, or implicitly through operations that require the vector
size to be modified.
Constructor Summary | |
VectorNd(double[] values)
Creates a vector from an array of doubles. |
|
VectorNd(int size)
Creates a vector of a specific size, and initializes its elements to 0. |
|
VectorNd(int size,
double[] values)
Creates a vector of a specific size, and initializes its elements from an array of values. |
|
VectorNd(VectorObject v)
Creates a vector whose size and elements are the same as an existing VectorObject. |
Method Summary | |
void |
absolute()
Sets the elements of this vector to their absolute values. |
void |
absolute(VectorNd v1)
Sets the elements of this vector to the absolute value of v1. |
void |
add(VectorNd v1)
Adds this vector to v1 and places the result in this vector. |
void |
add(VectorNd v1,
VectorNd v2)
Adds vector v1 to v2 and places the result in this vector. |
double |
angle(VectorNd v1)
Returns the angle between this vector and v1. |
void |
combine(double s1,
VectorNd v1,
double s2,
VectorNd v2)
Computes s1 v1 + s2 v2 and places
the result in this vector. |
double |
dot(VectorNd v1)
Returns the dot product of this vector and v1. |
boolean |
epsilonEquals(VectorNd v1,
double eps)
Returns true if the elements of this vector equal those of vector v1 within a
prescribed tolerance epsilon . |
boolean |
equals(VectorNd v1)
Returns true if the elements of this vector exactly equal those of vector v1 . |
void |
get(double[] values)
Copies the elements of this vector into an array of doubles. |
double |
get(int i)
Gets a single element of this vector. |
double[] |
getBuffer()
Returns the internal buffer used to store the elements in this vector. |
double |
infinityNorm()
Returns the infinity norm of this vector. |
void |
interpolate(double s,
VectorNd v1)
Computes the interpolation (1-s) this + s v1 and places
the result in this vector. |
void |
interpolate(VectorNd v1,
double s,
VectorNd v2)
Computes the interpolation (1-s) v1 + s v2 and places
the result in this vector. |
boolean |
isFixedSize()
Returns true if this vector is of fixed size. |
double |
maxElement()
Returns the maximum element value of this vector. |
double |
minElement()
Returns the minimum element value of this vector. |
void |
mul(MatrixNd M,
VectorNd b)
Multiplies matrix M by the vector b and places the result in this vector. |
void |
mulTranspose(MatrixNd M,
VectorNd b)
Multiplies the transpose of matrix M by the vector b and places the result in this vector. |
void |
negate()
Negates this vector in place. |
void |
negate(VectorNd v1)
Sets this vector to the negative of v1. |
double |
norm()
Returns the 2 norm of this vector. |
void |
normalize()
Normalizes this vector in place. |
void |
normalize(VectorNd v1)
Computes a unit vector in the direction of v1 and places the result in this vector. |
double |
normSquared()
Returns the square of the 2 norm of this vector. |
double |
oneNorm()
Returns the 1 norm of this vector. |
void |
scale(double s)
Scales the elements of this vector by s . |
void |
scale(double s,
VectorNd v1)
Scales the elements of vector v1 by s and places
the results in this vector. |
void |
scaleAdd(double s,
VectorNd v1)
Computes s this + v1 and places
the result in this vector. |
void |
scaleAdd(double s,
VectorNd v1,
VectorNd v2)
Computes s v1 + v2 and places
the result in this vector. |
void |
set(double[] values)
Sets the elements of this vector from an array of doubles. |
void |
set(int i,
double value)
Sets a single element of this vector. |
void |
set(VectorNd v1)
Sets the size and values of this vector to those of v1. |
void |
setBuffer(int size,
double[] buffer)
Explicitly sets the size and internal buffer associated with this vector. |
void |
setRandom()
Sets the elements of this vector to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive). |
void |
setRandom(double lower,
double upper)
Sets the elements of this vector to uniformly distributed random values in a specified range. |
void |
setRandom(double lower,
double upper,
java.util.Random generator)
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator. |
void |
setSize(int newSize)
Sets the size of this vector. |
void |
setZero()
Sets the elements of this vector to zero. |
int |
size()
Returns the size of this vector. |
void |
sort()
Sorts the contents of this vector by element value, from largest to smallest value. |
void |
sort(VectorNd v1)
Sorts the contents of vector v1 by element value, from largest to smallest value, and places the result into this vector. |
void |
sub(VectorNd v1)
Subtracts v1 from this vector and places the result in this vector. |
void |
sub(VectorNd v1,
VectorNd v2)
Subtracts vector v1 from v2 and places the result in this vector. |
void |
unsetBuffer()
Removes an explicit buffer provided for this vector and replaces it with a default implicit buffer. |
Methods inherited from class maspack.matrix.VectorObject |
dot, epsilonEquals, equals, equals, get, scan, set, toString, toString, toString |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public VectorNd(int size) throws ImproperSizeException
size
- size of the vector
ImproperSizeException
- if size is negativepublic VectorNd(int size, double[] values) throws ImproperSizeException
size
- size of the vectorvalues
- element values for the new vector
ImproperSizeException
- if size is negativepublic VectorNd(double[] values)
values
- element values for the new vectorpublic VectorNd(VectorObject v)
v
- vector object to be copied.Method Detail |
public double[] getBuffer()
Note that the buffer may be larger than the vector. The i-th element in the vector corresponds to the i-th entry in the buffer.
If this vector is resized, then the internal buffer may change and the buffer previously returned by this routine may no longer be valid.
setBuffer(int, double[])
public int size()
size
in class VectorObject
public boolean isFixedSize()
isFixedSize
in class VectorObject
setSize(int)
public void setSize(int newSize) throws ImproperSizeException
getBuffer
.
If a vector is resized, then previous element values which are still within the new vector dimension are preserved. Other (new) element values are undefined.
setSize
in class VectorObject
newSize
- new vector size
ImproperSizeException
- if this vector has an explicit
internal buffer and that buffer is too small for the
requested sizeVectorObject.isFixedSize()
public void setBuffer(int size, double[] buffer)
buffer
must equal or exceed the specified size.
The vector can continue to be resized as long as
the requested sizes do not exceed the buffer size.
size
- new vector sizebuffer
- explicit buffer for this vector
ImproperSizeException
- if the specified buffer
is too small for the requested sizeunsetBuffer()
public void unsetBuffer()
java.lang.IllegalStateException
- if this vector does
not have an explicit buffer given by
setBuffer
setBuffer(int, double[])
public double get(int i)
get
in class VectorObject
i
- element index
public void get(double[] values)
get
in class VectorObject
values
- array into which values are copiedpublic void set(int i, double value)
set
in class VectorObject
i
- element indexvalue
- element valuepublic void set(double[] values)
set
in class VectorObject
values
- array from which values are copiedpublic void set(VectorNd v1)
v1
- vector whose size and values are copied
ImproperSizeException
- if this vector needs resizing
but is of fixed sizepublic void add(VectorNd v1, VectorNd v2) throws ImproperSizeException
v1
- left-hand vectorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different
sizes, or if this vector needs resizing but is of fixed sizepublic void add(VectorNd v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and
v1 have different sizespublic void sub(VectorNd v1, VectorNd v2) throws ImproperSizeException
v1
- left-hand vectorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different
sizes, or if this vector needs resizing but is of fixed sizepublic void sub(VectorNd v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and
v1 have different sizespublic void negate(VectorNd v1)
v1
- vector to negate
ImproperSizeException
- if this vector needs
resizing but is of fixed sizepublic void negate()
public void scale(double s)
s
.
s
- scaling factorpublic void scale(double s, VectorNd v1)
s
and places
the results in this vector. This vector is resized if necessary.
s
- scaling factorv1
- vector to be scaled
ImproperSizeException
- if this vector needs
resizing but is of fixed sizepublic void interpolate(VectorNd v1, double s, VectorNd v2) throws ImproperSizeException
(1-s) v1 + s v2
and places
the result in this vector. This vector is resized if necessary.
v1
- left-hand vectors
- interpolation factorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different
sizes, or if this vector needs resizing but is of fixed sizepublic void interpolate(double s, VectorNd v1) throws ImproperSizeException
(1-s) this + s v1
and places
the result in this vector.
s
- interpolation factorv1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different
sizespublic void scaleAdd(double s, VectorNd v1, VectorNd v2) throws ImproperSizeException
s v1 + v2
and places
the result in this vector. This vector is resized if necessary.
s
- scaling factorv1
- vector to be scaledv2
- vector to be added
ImproperSizeException
- if v1 and v2 have different
sizes, or if this vector needs resizing but is of fixed sizepublic void scaleAdd(double s, VectorNd v1) throws ImproperSizeException
s this + v1
and places
the result in this vector.
s
- scaling factorv1
- vector to be added
ImproperSizeException
- if this vector and v1 have different
sizespublic void combine(double s1, VectorNd v1, double s2, VectorNd v2) throws ImproperSizeException
s1 v1 + s2 v2
and places
the result in this vector. This vector is resized if necessary.
s1
- left-hand scaling factorv1
- left-hand vectors2
- right-hand scaling factorv2
- right-hand vector
ImproperSizeException
- if v1 and v2 have different
sizes, or if this vector needs resizing but is of fixed sizepublic double norm()
norm
in class VectorObject
public double normSquared()
normSquared
in class VectorObject
public double maxElement()
maxElement
in class VectorObject
public double minElement()
minElement
in class VectorObject
public double infinityNorm()
infinityNorm
in class VectorObject
public double oneNorm()
oneNorm
in class VectorObject
public double dot(VectorNd v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different
sizespublic double angle(VectorNd v1) throws ImproperSizeException
acos(c)
, where c
is the dot product of unit vectors parallel to this vector and v1.
v1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different
sizespublic void normalize()
public void normalize(VectorNd v1)
v1
- vector to normalize
ImproperSizeException
- if this vector needs resizing
but is of fixed sizepublic boolean epsilonEquals(VectorNd v1, double eps) throws ImproperSizeException
v1
within a
prescribed tolerance epsilon
.
v1
- vector to compare witheps
- comparison tolerance
ImproperSizeException
public boolean equals(VectorNd v1) throws ImproperSizeException
v1
.
v1
- vector to compare with
ImproperSizeException
public void setZero()
public void absolute()
public void absolute(VectorNd v1)
v1
- vector to take the absolute value of
ImproperSizeException
- if this vector needs
resizing but is of fixed sizepublic void sort()
public void sort(VectorNd v1)
v1
- vector to sortpublic void mul(MatrixNd M, VectorNd b)
M
- left-hand matrixb
- right-hand vector
ImproperSizeException
- if the size of b does not equal the
number of columns of M, or if this vector needs resizing but is of
fixed sizepublic void mulTranspose(MatrixNd M, VectorNd b)
M
- left-hand matrixb
- right-hand vector
ImproperSizeException
- if the size of b does not equal the
number of rows of M, or if this vector needs resizing but is of
fixed sizepublic void setRandom()
public void setRandom(double lower, double upper)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)public void setRandom(double lower, double upper, java.util.Random generator)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |