|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.matrix.MatrixObject
Base class for matrices. It provides methods which allow one to set and get
various components of a matrix (individual elements, rows, columns,
submatrics), and to do various non-modifying queries such as finding out its
size, computing it's determinant, or comparing it with other matrices. There
are also methods for producing a string representation of the matrix and for
reading its contents from a tokenizer. There is an abstract method setSize
for resizing, which can be used unless the matrix size is
fixed (which can be determined using isFixedSize
).
This base class does not publicly support matrix operations such as
multiplication or addition. The reason for that is that subclasses may
implement matrices with a specific structure, which could then be
compromised by arbitrary operations. For instance, if a subclass of
MatrixObject
implements orthogonal matrices, then it would not
make sense for that class to allow an add
operation. Similarly,
if a subclass implemented symmetric matrices, then any multiplication
methods supported by that class should not be open to general matrices.
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 matrix elements, rows, and columns are
zero-based. The range of valid indices for a matrix of size m X n
is [0, ... , m-1]
and code>[0, ... , n-1].
Constructor Summary | |
MatrixObject()
|
Method Summary | |
abstract int |
colSize()
Returns the number of columns in this matrix. |
double |
determinant()
Returns the determinant of this matrix, which must be square |
boolean |
epsilonEquals(MatrixObject M1,
double epsilon)
Returns true if the elements of this matrix equal those of matrix M1 within a
prescribed tolerance epsilon . |
boolean |
equals(MatrixObject M1)
Returns true if the elements of this matrix exactly equal those of matrix M1 . |
boolean |
equals(java.lang.Object obj)
Returns true if this matrix and a specified object have the same class type and if all the elements are exactly equal. |
double |
frobeniusNorm()
Returns the Frobenius norm of this matrix. |
void |
get(double[] values)
Copies the elements of this matrix into an array of doubles. |
void |
get(double[][] values)
Copies the elements of this matrix into a 2-dimensional array of doubles. |
abstract double |
get(int i,
int j)
Gets a single element of this matrix. |
void |
getColumn(int j,
double[] values)
Copies a column of this matrix into an array of doubles. |
void |
getColumn(int j,
VectorObject v)
Copies a column of this matrix into a VectorObject . |
void |
getRow(int i,
double[] values)
Copies a row of this matrix into an array of doubles. |
void |
getRow(int i,
VectorObject v)
Copies a row of this matrix into a VectorObject . |
double |
infinityNorm()
Returns the infinity norm of this matrix. |
boolean |
isFixedSize()
Returns true if this matrix is of fixed size. |
double |
oneNorm()
Returns the 1 norm of this matrix. |
abstract int |
rowSize()
Returns the number of rows in this matrix. |
void |
scan(java.io.StreamTokenizer stok)
Sets the contents of this matrix to values read from a StreamTokenizer. |
void |
set(double[] values)
Sets the elements of this matrix from an array of doubles. |
void |
set(double[][] values)
Sets the elements of this matrix from a 2-dimensional array of doubles. |
abstract void |
set(int i,
int j,
double value)
Sets a single element of this matrix. |
void |
set(MatrixObject M)
Sets the size and values of this matrix to those of another matrix. |
void |
setColumn(int j,
double[] values)
Sets a column of this matrix from an array of doubles. |
void |
setColumn(int j,
VectorObject v)
Sets a column of this matrix from a VectorObject . |
void |
setRow(int i,
double[] values)
Set a row of this matrix from an array of doubles. |
void |
setRow(int i,
VectorObject v)
Sets a row of this matrix from a VectorObject . |
void |
setSize(int numRows,
int numCols)
Sets the size of this matrix. |
java.lang.String |
toString()
Returns a String representation of this matrix, using the default format "%g" (see toString(String) . |
java.lang.String |
toString(NumberFormat fmt)
Returns a String representation of this matrix, 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 matrix, 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 MatrixObject()
Method Detail |
public abstract int rowSize()
public abstract int colSize()
public abstract double get(int i, int j)
i
- element row indexj
- element column index
public void get(double[] values)
(i,j)
is stored at
location i*colSize()+j
.
values
- array into which values are copiedpublic void get(double[][] values)
values
- array into which values are copied
java.lang.IllegalArgumentException
- values
has inconsistent row sizes
ImproperSizeException
- dimensions of
values
do not match the size of this matrixpublic void getColumn(int j, double[] values)
j
- column indexvalues
- array into which the column is copiedpublic void getRow(int i, double[] values)
i
- row indexvalues
- array into which the row is copiedpublic void getColumn(int j, VectorObject v)
VectorObject
.
j
- column indexv
- vector into which the column is copied
ImproperSizeException
- vector's size not equal to the number
of matrix rows and the vector cannot be resizedpublic void getRow(int i, VectorObject v)
VectorObject
.
i
- row indexv
- vector into which the row is copied
ImproperSizeException
- vector's size not equal to the number
of matrix columns and the vector cannot be resizedpublic abstract void set(int i, int j, double value)
i
- element row indexj
- element column indexvalue
- element valuepublic void set(double[] values)
(i,j)
is stored at location
i*colSize()+j
.
values
- array from which values are copiedpublic void set(double[][] values)
values
- array from which values are copied
java.lang.IllegalArgumentException
- values
has inconsistent row sizes
ImproperSizeException
- dimensions of
values
do not match the size of this matrixpublic void set(MatrixObject M)
M
- matrix whose size and values are copied
ImproperSizeException
- matrices have different sizes
and this matrix cannot be resized accordinglypublic void setColumn(int j, double[] values)
j
- column indexvalues
- array from which column values are copiedpublic void setRow(int i, double[] values)
i
- row indexvalues
- array from which the row is copiedpublic void setColumn(int j, VectorObject v)
VectorObject
.
j
- column indexv
- vector from which the column is copied
ImproperSizeException
- vector's size not equal to the number
of matrix rowspublic void setRow(int i, VectorObject v)
VectorObject
.
i
- row indexv
- vector from which the row is copied
ImproperSizeException
- vector's size not equal to the number
of matrix columnspublic boolean isFixedSize()
setSize
, or
implicitly when used as a result for various matrix operations.
setSize(int, int)
public void setSize(int numRows, int numCols)
isFixedSize
returns false.
numRows
- new row sizenumCols
- new column size
java.lang.UnsupportedOperationException
- if this operation is not
supportedisFixedSize()
public double determinant() throws ImproperSizeException
ImproperSizeException
- if the matrix is not squarepublic boolean epsilonEquals(MatrixObject M1, double epsilon) throws ImproperSizeException
M1
within a
prescribed tolerance epsilon
.
M1
- matrix to compare withepsilon
- comparison tolerance
ImproperSizeException
public boolean equals(MatrixObject M1) throws ImproperSizeException
M1
.
M1
- matrix to compare with
ImproperSizeException
public boolean equals(java.lang.Object obj)
obj
- object to compare with
public double oneNorm()
public double infinityNorm()
public double frobeniusNorm()
public java.lang.String toString()
"%g"
(see toString(String)
.
public java.lang.String toString(java.lang.String fmtStr)
printf
style
format string. A new line is inserted between each row.
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 6 3.1 0 ]defines a 2 x 3 matrix.
If the matrix 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 matrix values are read
ImproperSizeException
- if this matrix has a fixed size
which is incompatible with the input, or if the sizes of
the specified rows are inconsistent
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |