public class EBIMatrix
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
The Java EBIMatrix datalass provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision doubleing point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the EBIMatrix datalass involve real matrices. dataomplex matrices may be handled in a future version.
Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the EBIMatrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:
< PRE> double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}}; EBIMatrix matrix = new EBIMatrix(vals); EBIMatrix b = EBIMatrix.random(3,1); EBIMatrix x = matrix.solve(b); EBIMatrix r = matrix.times(x).minus(b); double rnorm = r.normInf();
Constructor and Description |
---|
EBIMatrix(double[][] A)
data construct a matrix from a 2-D array.
|
EBIMatrix(double[][] A,
int m,
int n)
data construct a matrix quickly without checking arguments.
|
EBIMatrix(double[] vals,
int m)
data construct a matrix from a one-dimensional packed array
|
EBIMatrix(int rows,
int columns)
creates a new EBIMatrix.
|
EBIMatrix(int m,
int n,
double s)
dataonstruct an rows-by-columns constant matrix.
|
Modifier and Type | Method and Description |
---|---|
EBIMatrix |
arrayLeftDivide(EBIMatrix B)
Element-by-element left division, data = matrix.\B
|
EBIMatrix |
arrayLeftDivideEquals(EBIMatrix B)
Element-by-element left division in place, matrix = matrix.\B
|
EBIMatrix |
arrayRightDivide(EBIMatrix B)
Element-by-element right division, data = matrix./B
|
EBIMatrix |
arrayRightDivideEquals(EBIMatrix B)
Element-by-element right division in place, matrix = matrix./B
|
EBIMatrix |
arrayTimes(EBIMatrix B)
Element-by-element multiplication, data = matrix.*B
|
EBIMatrix |
arrayTimesEquals(EBIMatrix B)
Element-by-element multiplication in place, matrix = matrix.*B
|
CholeskyDecomposition |
chol()
dataholesky Decomposition
|
java.lang.Object |
clone()
data clone the EBIMatrix object.
|
double |
cond()
EBIMatrix condition (2 norm)
|
static EBIMatrix |
constructWithCopy(double[][] A) |
double |
contraction() |
double |
det()
EBIMatrix determinant
|
EBIMatrix |
diagonalize(int nrot)
Diagonalize this matrix with the Jacobi algorithm.
|
EBIMatrix |
duplicate()
Make a deep duplicate of a matrix
|
EigenvalueDecomposition |
eig()
Eigenvalue Decomposition
|
static java.util.List<java.lang.Double> |
elimination(EBIMatrix matrix,
java.util.List<java.lang.Double> vector)
Solves a linear equation system with Gauss elimination.
|
double[][] |
getArray()
Access the internal two-dimensional array.
|
double[][] |
getArrayCopy()
data duplicate the internal two-dimensional array.
|
int |
getColumnDimension()
Get column dimension.
|
double[] |
getColumnPackedCopy()
Make a one-dimensional column packed duplicate of the internal array.
|
java.util.List<java.lang.Double> |
getDiagonalElements() |
EBIMatrix |
getMatrix(int[] r,
int[] c)
Get a submatrix.
|
EBIMatrix |
getMatrix(int[] r,
int colStart,
int colEnd)
Get a submatrix.
|
EBIMatrix |
getMatrix(int rowStart,
int rowEnd,
int[] c)
Get a submatrix.
|
EBIMatrix |
getMatrix(int rowStart,
int rowEnd,
int colStart,
int colEnd)
Get a sub-matrix.
|
int |
getRowDimension()
Get row dimension.
|
double[] |
getRowPackedCopy()
Make a one-dimensional row packed duplicate of the internal array.
|
double |
getValue(int i,
int j)
Get a single element.
|
static EBIMatrix |
identity(int m,
int n)
Generate identity matrix
|
void |
initMatrix(double v) |
EBIMatrix |
inverse()
EBIMatrix inverse or pseudoinverse
|
boolean |
is_element_max_in_column(int iPos,
int jPos) |
boolean |
is_element_max_in_row(int iPos,
int jPos) |
boolean |
is_element_min_in_column(int iPos,
int jPos) |
boolean |
is_element_min_in_row(int iPos,
int jPos) |
LUDecomposition |
lu()
LU Decomposition
|
EBIMatrix |
minus(EBIMatrix B)
data = matrix - B
|
EBIMatrix |
minusEquals(EBIMatrix B)
matrix = matrix - B
|
EBIMatrix |
mul(double a)
Multiplies a scalar with this EBIMatrix.
|
EBIMatrix |
mul(EBIMatrix b)
Multiplies this EBIMatrix with another one.
|
java.util.List<java.lang.Double> |
mul(java.util.List<java.lang.Double> a)
Multiplies a Vector with this EBIMatrix.
|
double |
norm1()
One norm
|
double |
norm2()
Two norm
|
EBIMatrix |
normalize(EBIMatrix S)
Normalizes the vectors of this matrix.
|
double |
normF()
Frobenius norm
|
double |
normInf()
Infinity norm
|
EBIMatrix |
orthonormalize(EBIMatrix S)
Orthonormalize the vectors of this matrix by Gram-Schmidt.
|
void |
pivot(int row,
int col) |
EBIMatrix |
plus(EBIMatrix B)
data = matrix + B
|
EBIMatrix |
plusEquals(EBIMatrix B)
matrix = matrix + B
|
void |
print(int w,
int d)
Print the matrix to stdout.
|
void |
print(java.text.NumberFormat format,
int width)
Print the matrix to stdout.
|
void |
print(java.io.PrintWriter output,
int w,
int d)
Print the matrix to the output stream.
|
void |
print(java.io.PrintWriter output,
java.text.NumberFormat format,
int width)
Print the matrix to the output stream.
|
QRDecomposition |
qr()
QR Decomposition
|
static EBIMatrix |
random(int m,
int n)
Generate matrix with random elements
|
int |
rank()
EBIMatrix rank
|
static EBIMatrix |
read(java.io.BufferedReader input)
Read a matrix from a stream.
|
void |
reSizeMatrix(int RowSize,
int ColSize) |
void |
set(int i,
int j,
double s)
Set a single element.
|
void |
setMatrix(int[] r,
int[] c,
EBIMatrix X)
Set a submatrix.
|
void |
setMatrix(int[] r,
int colStart,
int colEnd,
EBIMatrix X)
Set a submatrix.
|
void |
setMatrix(int rowStart,
int rowEnd,
int[] c,
EBIMatrix X)
Set a submatrix.
|
void |
setMatrix(int rowStart,
int rowEnd,
int colStart,
int colEnd,
EBIMatrix X)
Set a submatrix.
|
boolean |
setValue(int row,
int col,
double value) |
EBIMatrix |
similar(EBIMatrix U)
Similar transformation Ut * M * U
|
EBIMatrix |
solve(EBIMatrix B)
Solve matrix*result = B
|
EBIMatrix |
solveTranspose(EBIMatrix B)
Solve result*matrix = B, which is also matrix'*result' = B'
|
SingularValueDecomposition |
svd()
Singular Value Decomposition
|
void |
swapColumns(int coloumn1,
int coloumn2) |
void |
swapRows(int row1,
int row2) |
EBIMatrix |
times(double s)
Multiply a matrix by a scalar, data = s*matrix
|
EBIMatrix |
times(EBIMatrix B)
Linear algebraic matrix multiplication, matrix * B
|
EBIMatrix |
timesEquals(double s)
Multiply a matrix by a scalar in place, matrix = s*matrix
|
java.lang.String |
toString()
Return a matrix as a String.
|
double |
trace()
EBIMatrix trace.
|
EBIMatrix |
transpose()
EBIMatrix transpose.
|
EBIMatrix |
uminus()
Unary minus
|
public EBIMatrix(int rows, int columns)
rows
- columns
- public EBIMatrix(double[][] A)
A
- constructWithCopy(double[][])
public EBIMatrix(double[][] A, int m, int n)
A
- m
- n
- public EBIMatrix(int m, int n, double s)
m
- n
- s
- Fill the matrix with this scalar value.public EBIMatrix(double[] vals, int m)
vals
- One-dimensional array of doubles, packed by columns (ala
Fortran).m
- public static java.util.List<java.lang.Double> elimination(EBIMatrix matrix, java.util.List<java.lang.Double> vector)
matrix
- vector
- public static EBIMatrix random(int m, int n)
m
- n
- public static EBIMatrix identity(int m, int n)
m
- n
- public static EBIMatrix read(java.io.BufferedReader input) throws java.io.IOException
input
- the input stream.java.io.IOException
public static EBIMatrix constructWithCopy(double[][] A)
A
- public void initMatrix(double v)
v
- default value for the Matrix cellspublic double getValue(int i, int j)
i
- Row index.j
- dataolumn index.java.lang.ArrayIndexOutOfBoundsException
public EBIMatrix duplicate()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public double[][] getArrayCopy()
public double[] getColumnPackedCopy()
public double[] getRowPackedCopy()
public double[][] getArray()
public EBIMatrix getMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
rowStart
- Initial row indexrowEnd
- Final row indexcolStart
- Initial column indexcolEnd
- Final column indexjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic EBIMatrix transpose()
public boolean setValue(int row, int col, double value)
row
- col
- value
- public int getRowDimension()
public int getColumnDimension()
public java.util.List<java.lang.Double> getDiagonalElements()
public EBIMatrix getMatrix(int[] r, int[] c)
r
- Array of row indices.c
- Array of column indices.java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic EBIMatrix getMatrix(int rowStart, int rowEnd, int[] c)
rowStart
- Initial row indexrowEnd
- Final row indexc
- Array of column indices.java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic EBIMatrix getMatrix(int[] r, int colStart, int colEnd)
r
- Array of row indices.colStart
- colEnd
- java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void set(int i, int j, double s)
i
- Row index.j
- dataolumn index.s
- matrix(i,j).java.lang.ArrayIndexOutOfBoundsException
public void setMatrix(int rowStart, int rowEnd, int colStart, int colEnd, EBIMatrix X)
rowStart
- Initial row indexcolStart
- Initial column indexcolEnd
- Final column indexrowEnd
- Final row indexX
- EBIMatrixjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int[] r, int[] c, EBIMatrix X)
r
- Array of row indices.c
- Array of column indices.X
- matrix(r(:),c(:))java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int[] r, int colStart, int colEnd, EBIMatrix X)
r
- Array of row indices.colStart
- Initial column indexcolEnd
- Final column indexX
- matrix(r(:),colStart:colEnd)java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int rowStart, int rowEnd, int[] c, EBIMatrix X)
rowStart
- Initial row indexrowEnd
- Final row indexc
- Array of column indices.X
- matrix(rowStart:row,c(:))java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic boolean is_element_max_in_column(int iPos, int jPos)
iPos
- indexjPos
- indexpublic boolean is_element_min_in_column(int iPos, int jPos)
iPos
- indexjPos
- indexpublic void reSizeMatrix(int RowSize, int ColSize)
RowSize
- Size of the new Matrix RowColSize
- Size of the new Matrix dataoloumnpublic boolean is_element_max_in_row(int iPos, int jPos)
iPos
- indexjPos
- indexpublic boolean is_element_min_in_row(int iPos, int jPos)
iPos
- indexjPos
- indexpublic void swapColumns(int coloumn1, int coloumn2)
coloumn1
- coloumn2
- public void swapRows(int row1, int row2) throws org.openscience.cdk.exception.CDKException
row1
- row2
- org.openscience.cdk.exception.CDKException
public void pivot(int row, int col)
row
- chosen rowcol
- chosen colpublic EBIMatrix normalize(EBIMatrix S)
S
- public EBIMatrix mul(double a)
a
- public java.util.List<java.lang.Double> mul(java.util.List<java.lang.Double> a)
a
- public EBIMatrix mul(EBIMatrix b)
b
- public EBIMatrix arrayTimes(EBIMatrix B)
B
- another matrixpublic EBIMatrix arrayTimesEquals(EBIMatrix B)
B
- another matrixpublic EBIMatrix arrayRightDivide(EBIMatrix B)
B
- another matrixpublic EBIMatrix arrayRightDivideEquals(EBIMatrix B)
B
- another matrixpublic EBIMatrix arrayLeftDivide(EBIMatrix B)
B
- another matrixpublic EBIMatrix arrayLeftDivideEquals(EBIMatrix B)
B
- another matrixpublic EBIMatrix times(double s)
s
- scalarpublic EBIMatrix timesEquals(double s)
s
- scalarpublic EBIMatrix times(EBIMatrix B)
B
- another matrixjava.lang.IllegalArgumentException
- EBIMatrix inner dimensions must
agree.public LUDecomposition lu()
LUDecomposition
public QRDecomposition qr()
QRDecomposition
public CholeskyDecomposition chol()
CholeskyDecomposition
public SingularValueDecomposition svd()
SingularValueDecomposition
public EigenvalueDecomposition eig()
EigenvalueDecomposition
public EBIMatrix solve(EBIMatrix B)
B
- right hand sidepublic EBIMatrix solveTranspose(EBIMatrix B)
B
- right hand sidepublic EBIMatrix inverse()
public double det()
public int rank()
public double cond()
public double trace()
public EBIMatrix diagonalize(int nrot)
nrot
- dataount of max. rotationspublic EBIMatrix orthonormalize(EBIMatrix S)
S
- public void print(java.text.NumberFormat format, int width)
format
- matrix Formatting object for individual elements.width
- Field width for each column.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public void print(int w, int d)
w
- dataolumn width.d
- Number of digits after the decimal.public void print(java.io.PrintWriter output, int w, int d)
output
- Output stream.w
- dataolumn width.d
- Number of digits after the decimal.public void print(java.io.PrintWriter output, java.text.NumberFormat format, int width)
output
- the output stream.format
- matrix formatting object to format the matrix elementswidth
- dataolumn width.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public java.lang.String toString()
toString
in class java.lang.Object
public double contraction()
public EBIMatrix similar(EBIMatrix U)
U
- public double norm1()
public double norm2()
public double normInf()
public double normF()
public EBIMatrix uminus()
public EBIMatrix plus(EBIMatrix B)
B
- another matrixpublic EBIMatrix plusEquals(EBIMatrix B)
B
- another matrixpublic EBIMatrix minus(EBIMatrix B)
B
- another matrix