|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.matrix.VectorObject
Base class for vectors. It provides methods which allow one to set and get
elements of a vector, to do various non-modifying queries such as finding
out its size, computing it's norms, or comparing it with other
vectors. There are also methods fo producing a string representation of the
vector and for reading its contents from a tokenizer. There is an abstract
method setSize
for resizing, which can be used unless the
vector size is fixed (which can be determined using isFixedSize
).
This base class does not publicly support vector operations such as
addition or scaling. The reason for that is that subclasses may implement
vectors with a specific structure, which could then be compromised by
arbitrary operations. For instance, if a subclass of
VectorObject
implements unit vectors, it would not
make sense for that class to allow an add
operation.
Of course, it is possible to corrupt any special subclass structure
using the set
methods provided in this base class, but it was
felt that not including such routines would be overly restrictive. It is
therefore up to the user to safeguard subclass integrity when using them.
Note that indices for vector elements are zero-based, so
that the range of valid indices for a vector of length n
is [0, ... , n-1]
.
Constructor Summary | |
VectorObject()
|
Method Summary | |
double |
dot(VectorObject v1)
Returns the dot product of this vector and v1. |
boolean |
epsilonEquals(VectorObject v1,
double eps)
Returns true if the elements of this vector equal those of vector v1 within a
prescribed tolerance epsilon . |
boolean |
equals(java.lang.Object obj)
Returns true if this vector and a specified object have the same class type and if all the elements are exactly equal. |
boolean |
equals(VectorObject 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. |
abstract double |
get(int i)
Gets a single element of this vector. |
void |
get(VectorObject v1)
Copies the elements of this vector into another vector object. |
double |
infinityNorm()
Returns the infinity norm of this vector. |
boolean |
isFixedSize()
Returns true if this vector is of fixed size. |
double |
maxElement()
Returns the maximum element value. |
double |
minElement()
Returns the minimum element value. |
double |
norm()
Returns the 2 norm of this vector. |
double |
normSquared()
Returns the square of the 2 norm of this vector. |
double |
oneNorm()
Returns the 1 norm of this vector. |
void |
scan(java.io.StreamTokenizer stok)
Sets the contents of this vector to values read from a StreamTokenizer. |
void |
set(double[] values)
Sets the elements of this vector from an array of doubles. |
abstract void |
set(int i,
double value)
Sets a single element of this vector. |
void |
set(VectorObject v)
Sets the values of this vector to those of another vector. |
void |
setSize(int n)
Sets the size of this vector. |
abstract int |
size()
Returns the number of elements in this vector. |
java.lang.String |
toString()
Returns a String representation of this vector, using the default format "%g" (see toString(String) . |
java.lang.String |
toString(NumberFormat fmt)
Returns a String representation of this vector, in which each element is formated using a C printf style as decribed
by the parameter NumberFormat . |
java.lang.String |
toString(java.lang.String fmtStr)
Returns a String representation of this vector, in which each element is formated using a C printf style format
string. |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public VectorObject()
Method Detail |
public abstract int size()
public abstract double get(int i)
i
- element index
public void get(double[] values)
values
- array into which values are copiedpublic void get(VectorObject v1) throws ImproperSizeException
v1
- vector object into which values are copied
ImproperSizeExcept - if the vector objects have different
sizes
ImproperSizeException
public abstract void set(int i, double value)
i
- element indexvalue
- element valuepublic void set(double[] values)
values
- array from which values are copiedpublic void set(VectorObject v)
v
- vector from which values are copied
ImproperSizeException
- vectors have different sizes
and this vector cannot be resized accordinglypublic boolean isFixedSize()
setSize
, or
implicitly when used as a result for various vector operations.
setSize(int)
public void setSize(int n)
isFixedSize
returns false.
n
- new size
java.lang.UnsupportedOperationException
- if this operation is not
supportedisFixedSize()
public double norm()
public double normSquared()
public double oneNorm()
public double infinityNorm()
public double maxElement()
public double minElement()
public double dot(VectorObject v1) throws ImproperSizeException
v1
- right-hand vector
ImproperSizeException
- if this vector and v1 have different
sizespublic boolean epsilonEquals(VectorObject v1, double eps) throws ImproperSizeException
v1
within a
prescribed tolerance epsilon
.
v1
- vector to compare witheps
- comparison tolerance
ImproperSizeException
public boolean equals(VectorObject v1) throws ImproperSizeException
v1
.
v1
- vector to compare with
ImproperSizeException
public boolean equals(java.lang.Object obj)
obj
- object to compare with
public java.lang.String toString()
"%g"
(see toString(String)
.
public java.lang.String toString(java.lang.String fmtStr)
printf
style format
string. For a description of the format string syntax, see NumberFormat
.
fmtStr
- numeric format specification
public java.lang.String toString(NumberFormat fmt)
printf
style as decribed
by the parameter NumberFormat
. When called numerous
times, this routine can be more efficient than toString(String)
, because the NumberFormat
does not need to be recreated each time
from a specification string.
fmt
- numeric format
public void scan(java.io.StreamTokenizer stok) throws java.io.IOException
[ 1.2 4 5 3.1 ]defines a vector of size 4.
If the vector is not of fixed-size, it will be resized
to fit the input.
The StreamTokenizer will be set by this method to parse numbers, and
it should already be configured to recognize the characters
'+'
and -
as tokens.
Note:This method disables numeric parsing in the StreamTokenizer. This is because the method does its own numeric parsing, in order to handle exponents.
stok
- Tokenizer from which vector values are read
ImproperSizeException
- if this vector has a fixed size
which is incompatible with the input
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |