|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsugr.linalg.MatrixImplJama
Matrix class. Contains operations of linear algebra: Addition/Substraction, Multiplication, get/set-methods (all double precision floating points), printing, Inversion, submatrices-access, transpose, vectorize.
Construction of matrices is also possible. You are allowed to use LinearAlgebraFactory-methods for constructing matrices and vector. For more information about this class, you are invited to read more here in sugr.linalg.LinearAlgebraFactory
Just a note: In further documentation, matrix A is synonym for this matrix, e.g.:
Matrix firstMatrix; Matrix secondMatrix; Matrix C = firstMatrix.add(secondMatrix);means for add(Matrix B): firstMatrix is this matrix = A, secondMatrix is B
Field Summary | |
protected Jama.Matrix |
impl
Jama.Matrix is embedded into this class - all operations are mapped to that. |
private static long |
serialVersionUID
Class version number for serialization |
Constructor Summary | |
MatrixImplJama()
Standard-constructor. |
|
MatrixImplJama(double[][] values)
create a new matrix by a given double precision floating point array. |
|
MatrixImplJama(int no_rows,
int no_cols)
Creates a new matrix containing only zeros |
|
MatrixImplJama(Matrix M)
create B from A. |
Method Summary | |
java.lang.Object |
clone()
Clone a matrix. |
Matrix |
copy()
Create a new matrix B, independent from A |
Matrix |
delColumn(int col)
delete a column from A. |
Matrix |
delRow(int row)
delete a row from A. |
double |
det()
Computes the determinant of the matrix |
double[] |
eig()
EigenvalueDecomposition of this Matrix |
boolean |
equals(java.lang.Object obj)
Test, whether A and B are identical or not |
double |
get(int row,
int col)
Get a single element |
Vector |
getColumn(int j)
|
int |
getColumnDimension()
Like the name says :-) |
Matrix |
getMatrix(int i0,
int i1,
int j0,
int j1)
Returns a Submatrix with dimension (i1-i0) x (j1-j0) Upper left element begin with indices (0,0) |
Vector |
getRow(int i)
|
int |
getRowDimension()
Like the name says :-) |
Matrix |
invert()
Matrix inverse or pseudoinverse |
boolean |
isSemiDefinite()
Test, whether A ist semidefinit or not |
Matrix |
kronecker(Matrix B)
Calculates the kronecker-product of two matrices. |
Matrix |
minus(Matrix B)
C=A-B |
Matrix |
mult(double f)
B=A*f , where f is a scalar |
Matrix |
mult(Matrix B)
C=A*B |
Vector |
mult(Vector v)
B=A*v, where v is a vector. |
Matrix |
plus(Matrix B)
C=A+B |
void |
print()
Prints this matrix to stdout |
void |
print(int w,
int d)
Prints this matrix to stdout It may be useful to select w > d. |
void |
printMatlab()
Prints this matrix in Matlab format to stdout |
Matrix |
pseudoInverse(int rank)
returns the pseudo-inverse A^+ . |
Matrix |
pseudoInverse(Matrix H)
returns the pseudo-inverse A^+ with given Nullspace |
Matrix[] |
qr()
Computes the QR Decomposition of given Matrix |
void |
set(double value)
Sets all elements of the matrix to the given value. |
void |
set(int row,
int col,
double value)
Set a single element |
void |
setColumn(int j,
Vector v)
|
void |
setRow(int i,
Vector v)
|
Matrix |
slice(int[] listOfRows,
int[] listOfCols)
Get submatrix with given list of rows and given list of columns. |
void |
slice(int[] listOfRows,
int[] listOfCols,
Matrix B)
As other slice, only: read values from Matrix B and put them in the object at the posisitions of the intersections of given rows and columns. |
Matrix |
slice(int i0,
int i1,
int j0,
int j1)
Gets a submatrix of A with B |
void |
slice(int i0,
int i1,
int j0,
int j1,
Matrix B)
Sets a submatrix |
Vector |
solve(Vector y)
|
Matrix[] |
svd()
Computes the SingularValueDecomposition of given Matrix with dimension m x n (m>=n), so the result is given by: Matrix = U*S*V^t |
java.lang.String |
toString()
Delivers a string with the elements of the matrix. |
Matrix |
trans()
Matrix transpose |
Vector |
vec()
returns the matrix as a vector: First the first column, then the second column and so on. |
Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final long serialVersionUID
protected Jama.Matrix impl
Constructor Detail |
public MatrixImplJama(int no_rows, int no_cols)
no_rows
- number of rows the matrix should haveno_cols
- number of rows the matrix should havepublic MatrixImplJama(double[][] values)
double[][] array = { {0,1,2,3}, {0,1,2,3}, {0,1,2,3}}; Matrix A = new Matrix(array);Matrix A has dimension 3x4.
values
- given in doublepublic MatrixImplJama(Matrix M)
public MatrixImplJama()
Method Detail |
public Matrix plus(Matrix B)
C=A+B
plus
in interface Matrix
B
- Must have same dimensions like this matrix
public Matrix minus(Matrix B)
C=A-B
minus
in interface Matrix
B
- Must have same dimensions like this matrix
public Matrix mult(Matrix B)
C=A*B
mult
in interface Matrix
B
- rowDim of B must be the same like colDim from A
public Matrix trans()
Matrix transpose
trans
in interface Matrix
public double get(int row, int col)
Get a single element
get
in interface Matrix
row
- row-index
col
- column-index
public void set(int row, int col, double value)
Set a single element
set
in interface Matrix
row
- row-index
col
- column-index
value
- A(i,j):=value
public int getRowDimension()
Like the name says :-)
getRowDimension
in interface Matrix
public int getColumnDimension()
Like the name says :-)
getColumnDimension
in interface Matrix
public Matrix invert()
Matrix inverse or pseudoinverse
invert
in interface Matrix
public Matrix mult(double f)
B=A*f , where f is a scalar
mult
in interface Matrix
f
- scalar, given as double
public Vector mult(Vector v)
B=A*v, where v is a vector. Dimension of v and column dimension of A must agree
mult
in interface Matrix
v
- Vector, with dimension the same as column-dimension of A
public Matrix[] svd()
Computes the SingularValueDecomposition of given Matrix with dimension m x n (m>=n), so the result is given by: Matrix = U*S*V^t
svd
in interface Matrix
orig_matrix = Matrix[0].mult(Matrix[1]).mult(Matrix[2].trans());gives the original matrix
public Matrix slice(int[] listOfRows, int[] listOfCols)
Get submatrix with given list of rows and given list of columns. If listofRows is emtpy, get complete column, if listOfCols is empty, get complete rows.
slice
in interface Matrix
listOfRows
- ...
listOfCols
- ...
public void slice(int[] listOfRows, int[] listOfCols, Matrix B)
As other slice, only: read values from Matrix B and put them in the object at the posisitions of the intersections of given rows and columns.
slice
in interface Matrix
listOfRows
- ...
listOfCols
- ...
B
- ...
public void slice(int i0, int i1, int j0, int j1, Matrix B)
slice
in interface Matrix
i0
- initial row index (upper left is (0,0) )i1
- final row indexj0
- initial column indexj1
- final column indexB
- Matrix with dimension (i1-i0+1 x j1-j0+1)public Vector vec()
e.g. : if A = | a b | then A.vec() returns | a | | c d | | c | | b | | d |
vec
in interface Matrix
public Matrix copy()
copy
in interface Matrix
public void set(double value)
Sets all elements of the matrix to the given value.
set
in interface Matrix
value
- public void print(int w, int d)
Prints this matrix to stdout
It may be useful to select w > d. A common value is w=5, d=3
print
in interface Matrix
w
- describes the width of a single elementd
- number of decimals after commapublic void print()
Prints this matrix to stdout
print
in interface Matrix
public void printMatlab()
Prints this matrix in Matlab format to stdout
printMatlab
in interface Matrix
public java.lang.String toString()
toString
in interface Matrix
public boolean equals(java.lang.Object obj)
equals
in interface Matrix
obj
- Matrix to test
public Matrix getMatrix(int i0, int i1, int j0, int j1)
Returns a Submatrix with dimension (i1-i0) x (j1-j0) Upper left element begin with indices (0,0)
getMatrix
in interface Matrix
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column index
public double[] eig()
eig
in interface Matrix
public boolean isSemiDefinite()
isSemiDefinite
in interface Matrix
public Matrix pseudoInverse(int rank)
pseudoInverse
in interface Matrix
rank
- the rank which A with the given elements should have
public Matrix kronecker(Matrix B)
|a_11*B ... a_1m*B | C = |... ... | |a_n1*B ... a_nm*B |
kronecker
in interface Matrix
B
- an arbitrary matrix
public double det()
det
in interface Matrix
public Vector getColumn(int j)
getColumn
in interface Matrix
public Vector getRow(int i)
getRow
in interface Matrix
public void setRow(int i, Vector v)
setRow
in interface Matrix
public void setColumn(int j, Vector v)
setColumn
in interface Matrix
public Vector solve(Vector y)
solve
in interface Matrix
public Matrix delColumn(int col)
e.g. : if A looks like | a11 a12 a13 | | a21 a22 a23 | 3x3 Matrix | a31 a32 a33 | then A.delColumn(0) returns | a12 a13 | | a22 a23 | 3x2 Matrix | a32 a33 |
delColumn
in interface Matrix
col
- column to delete. Must be between 0 and m-1, if A is nxm
public Matrix delRow(int row)
e.g. : if A looks like | a11 a12 a13 | | a21 a22 a23 | 3x3 Matrix | a31 a32 a33 | then A.delRow(0) returns | a21 a22 a23 | 2x3 Matrix | a31 a32 a33 |
delRow
in interface Matrix
row
- row to delete. Must be between 0 and n-1, if A is nxm
public Matrix slice(int i0, int i1, int j0, int j1)
slice
in interface Matrix
i0
- initial row index (upper left is (0,0) )i1
- final row indexj0
- initial column indexj1
- final column indexpublic Matrix[] qr()
Computes the QR Decomposition of given Matrix
qr
in interface Matrix
public java.lang.Object clone()
clone
in interface Matrix
public Matrix pseudoInverse(Matrix H)
Matrix
returns the pseudo-inverse A^+ with given Nullspace
pseudoInverse
in interface Matrix
H
- nullspace
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |