|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mpv2.AllMatrices mpv2.JamaMatrix
public class JamaMatrix
Jama = Java Matrix class.
The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating 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 Matrix Class involve real matrices. Complex 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 Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:
double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}}; JamaMatrix A = new JamaMatrix(vals); JamaMatrix b = JamaMatrix.random(3,1); JamaMatrix x = A.solve(b); JamaMatrix r = A.times(x).minus(b); double rnorm = r.normInf();
Field Summary |
---|
Fields inherited from class mpv2.AllMatrices |
---|
K, N |
Constructor Summary | |
---|---|
JamaMatrix(AllMatrices B)
Construct a new matrix from another matrix (of any kind) if argument B is an object of class JamaMatrix this is the same as (deep) copy (or clone). |
|
JamaMatrix(double[][] A)
Construct a matrix from a 2-D array. |
|
JamaMatrix(double[][] A,
int m,
int n)
Construct a matrix quickly without checking arguments. |
|
JamaMatrix(double[] vals,
int m)
Construct a matrix from a one-dimensional packed array |
|
JamaMatrix(int m,
int n)
Construct an m-by-n matrix of zeros. |
|
JamaMatrix(int m,
int n,
double s)
Construct an m-by-n constant matrix. |
Method Summary | |
---|---|
JamaMatrix |
arrayLeftDivide(JamaMatrix B)
Element-by-element left division, C = A. |
JamaMatrix |
arrayLeftDivideEquals(JamaMatrix B)
Element-by-element left division in place, A = A. |
JamaMatrix |
arrayRightDivide(JamaMatrix B)
Element-by-element right division, C = A. |
JamaMatrix |
arrayRightDivideEquals(JamaMatrix B)
Element-by-element right division in place, A = A. |
JamaMatrix |
arrayTimes(JamaMatrix B)
Element-by-element multiplication, C = A. |
JamaMatrix |
arrayTimesEquals(JamaMatrix B)
Element-by-element multiplication in place, A = A. |
CholeskyDecomposition |
chol()
Cholesky Decomposition |
java.lang.Object |
clone()
Clone the JamaMatrix object. |
double |
cond()
Matrix condition (2 norm) |
static JamaMatrix |
constructWithCopy(double[][] A)
Construct a matrix from a copy of a 2-D array. |
JamaMatrix |
copy()
Make a deep copy of a matrix |
double |
det()
Matrix determinant |
EigenvalueDecomposition |
eig()
Eigenvalue Decomposition |
double |
get(int i,
int j)
Get a single element. |
void |
getAll(double[] vals)
Get all entries of the matrix into argument vals in a column-packed way. |
double[][] |
getArray()
Access the internal two-dimensional array. |
double[][] |
getArrayCopy()
Copy the internal two-dimensional array. |
int |
getColumnDimension()
Get column dimension. |
double[] |
getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array. |
JamaMatrix |
getMatrix(int[] r,
int[] c)
Get a submatrix. |
JamaMatrix |
getMatrix(int[] r,
int j0,
int j1)
Get a submatrix. |
JamaMatrix |
getMatrix(int i0,
int i1,
int[] c)
Get a submatrix. |
JamaMatrix |
getMatrix(int i0,
int i1,
int j0,
int j1)
Get a submatrix. |
void |
getRow(int rowNumber,
double[] x)
Get a row of the matrix into argument x. |
int |
getRowDimension()
Get row dimension. |
double[] |
getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array. |
static JamaMatrix |
identity(int m,
int n)
Generate identity matrix |
JamaMatrix |
inverse()
Matrix inverse or pseudoinverse |
LUDecomposition |
lu()
LU Decomposition |
JamaMatrix |
minus(JamaMatrix B)
C = A - B |
JamaMatrix |
minusEquals(JamaMatrix B)
A = A - B |
double |
norm1()
One norm |
double |
norm2()
Two norm |
double |
normF()
Frobenius norm |
double |
normInf()
Infinity norm |
JamaMatrix |
plus(JamaMatrix B)
C = A + B |
JamaMatrix |
plusEquals(JamaMatrix B)
A = A + 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 JamaMatrix |
random(int m,
int n)
Generate matrix with random elements |
int |
rank()
Matrix rank |
static JamaMatrix |
read(java.io.BufferedReader input)
Read a matrix from a stream. |
void |
set(int i,
int j,
double s)
Set a single element. |
void |
setAll(double[] vals)
Set all entries of the matrix to the supplied new values. |
void |
setMatrix(int[] r,
int[] c,
JamaMatrix X)
Set a submatrix. |
void |
setMatrix(int[] r,
int j0,
int j1,
JamaMatrix X)
Set a submatrix. |
void |
setMatrix(int i0,
int i1,
int[] c,
JamaMatrix X)
Set a submatrix. |
void |
setMatrix(int i0,
int i1,
int j0,
int j1,
JamaMatrix X)
Set a submatrix. |
void |
setRow(int rowNumber,
double[] x)
Copy an array (x) into a row of the matrix. |
JamaMatrix |
solve(JamaMatrix B)
Solve A*X = B |
JamaMatrix |
solveTranspose(JamaMatrix B)
Solve X*A = B, which is also A'*X' = B' |
SingularValueDecomposition |
svd()
Singular Value Decomposition |
JamaMatrix |
times(double s)
Multiply a matrix by a scalar, C = s*A |
JamaMatrix |
times(JamaMatrix B)
Linear algebraic matrix multiplication, A * B |
JamaMatrix |
timesEquals(double s)
Multiply a matrix by a scalar in place, A = s*A |
double |
trace()
Matrix trace. |
JamaMatrix |
transpose()
JamaMatrix transpose. |
JamaMatrix |
uminus()
Unary minus |
Methods inherited from class mpv2.AllMatrices |
---|
addColumn, columnNorm0, columnNorm1, columnNorm2, columnNormInf, eqConstant, eqCopy, eqCopy, eqCopy, eqCopy, eqCopy, eqDifference, eqEProduct, eqEQuotient, eqIdentity, eqInverse, eqIProduct, eqNegate, eqOnes, eqPermuteColumns, eqPermuteRows, eqProduct, eqProduct, eqRandom, eqScaleColumns, eqScaleRows, eqSum, eqTProduct, eqTranspose, eqZeros, getAll, getColumn, getColumn, getK, getN, getRow, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, innerProduct, lup, pluseqOuterProduct, setColumn, setValue, sumAll, times, times, times, times, transposeTimes, transposeTimes, transposeTimes, transposeTimes |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JamaMatrix(int m, int n)
m
- Number of rows.n
- Number of colums.public JamaMatrix(int m, int n, double s)
m
- Number of rows.n
- Number of colums.s
- Fill the matrix with this scalar value.public JamaMatrix(double[][] A)
A
- Two-dimensional array of doubles.
java.lang.IllegalArgumentException
- All rows must have the same lengthconstructWithCopy(double[][])
public JamaMatrix(double[][] A, int m, int n)
A
- Two-dimensional array of doubles.m
- Number of rows.n
- Number of colums.public JamaMatrix(double[] vals, int m)
vals
- One-dimensional array of doubles, packed by columns (ala Fortran).m
- Number of rows.
java.lang.IllegalArgumentException
- Array length must be a multiple of m.public JamaMatrix(AllMatrices B)
B
- a matrix of any kind, class is a subclass of AllMatricescopy()
Method Detail |
---|
public void getRow(int rowNumber, double[] x)
getRow
in class AllMatrices
rowNumber
- number of the row in the matrix.x
- is set to the given row of matrix.
java.lang.IllegalArgumentException
public void getAll(double[] vals)
getAll
in class AllMatrices
vals
- an one-dimensional array where the values are copied into
java.lang.IllegalArgumentException
public void setRow(int rowNumber, double[] x)
0 <= n < N
.
setRow
in class AllMatrices
rowNumber
- number of the row in the matrix A
.x
- the given row of matrix A
.
java.lang.IllegalArgumentException
public void setAll(double[] vals)
setAll
in class AllMatrices
vals
- One-dimensional array of doubles, packed by columns (ala Fortran).
java.lang.IllegalArgumentException
public static JamaMatrix constructWithCopy(double[][] A)
A
- Two-dimensional array of doubles.
java.lang.IllegalArgumentException
- All rows must have the same lengthpublic JamaMatrix copy()
public java.lang.Object clone()
clone
in class java.lang.Object
public double[][] getArray()
public double[][] getArrayCopy()
public double[] getColumnPackedCopy()
public double[] getRowPackedCopy()
public int getRowDimension()
getRowDimension
in class AllMatrices
public int getColumnDimension()
getColumnDimension
in class AllMatrices
public double get(int i, int j)
get
in class AllMatrices
i
- Row index.j
- Column index.
java.lang.ArrayIndexOutOfBoundsException
public JamaMatrix getMatrix(int i0, int i1, int j0, int j1)
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column index
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic JamaMatrix getMatrix(int[] r, int[] c)
r
- Array of row indices.c
- Array of column indices.
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic JamaMatrix getMatrix(int i0, int i1, int[] c)
i0
- Initial row indexi1
- Final row indexc
- Array of column indices.
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic JamaMatrix getMatrix(int[] r, int j0, int j1)
r
- Array of row indices.j0
- Initial column indexj1
- Final column index
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void set(int i, int j, double s)
set
in class AllMatrices
i
- Row index.j
- Column index.s
- A(i,j).
java.lang.ArrayIndexOutOfBoundsException
public void setMatrix(int i0, int i1, int j0, int j1, JamaMatrix X)
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column indexX
- A(i0:i1,j0:j1)
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int[] r, int[] c, JamaMatrix X)
r
- Array of row indices.c
- Array of column indices.X
- A(r(:),c(:))
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int[] r, int j0, int j1, JamaMatrix X)
r
- Array of row indices.j0
- Initial column indexj1
- Final column indexX
- A(r(:),j0:j1)
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void setMatrix(int i0, int i1, int[] c, JamaMatrix X)
i0
- Initial row indexi1
- Final row indexc
- Array of column indices.X
- A(i0:i1,c(:))
java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic JamaMatrix transpose()
public double norm1()
norm1
in class AllMatrices
public double norm2()
norm2
in class AllMatrices
public double normInf()
normInf
in class AllMatrices
public double normF()
normF
in class AllMatrices
public JamaMatrix uminus()
public JamaMatrix plus(JamaMatrix B)
B
- another matrix
public JamaMatrix plusEquals(JamaMatrix B)
B
- another matrix
public JamaMatrix minus(JamaMatrix B)
B
- another matrix
public JamaMatrix minusEquals(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayTimes(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayTimesEquals(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayRightDivide(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayRightDivideEquals(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayLeftDivide(JamaMatrix B)
B
- another matrix
public JamaMatrix arrayLeftDivideEquals(JamaMatrix B)
B
- another matrix
public JamaMatrix times(double s)
s
- scalar
public JamaMatrix timesEquals(double s)
s
- scalar
public JamaMatrix times(JamaMatrix B)
B
- another matrix
java.lang.IllegalArgumentException
- Matrix inner dimensions must agree.public LUDecomposition lu()
lu
in class AllMatrices
LUDecomposition
public QRDecomposition qr()
qr
in class AllMatrices
QRDecomposition
public CholeskyDecomposition chol()
chol
in class AllMatrices
CholeskyDecomposition
public SingularValueDecomposition svd()
svd
in class AllMatrices
SingularValueDecomposition
public EigenvalueDecomposition eig()
eig
in class AllMatrices
EigenvalueDecomposition
public JamaMatrix solve(JamaMatrix B)
B
- right hand side
public JamaMatrix solveTranspose(JamaMatrix B)
B
- right hand side
public JamaMatrix inverse()
public double det()
det
in class AllMatrices
public int rank()
rank
in class AllMatrices
public double cond()
cond
in class AllMatrices
public double trace()
trace
in class AllMatrices
public static JamaMatrix random(int m, int n)
m
- Number of rows.n
- Number of colums.
public static JamaMatrix identity(int m, int n)
m
- Number of rows.n
- Number of colums.
public void print(int w, int d)
print
in class AllMatrices
w
- Column width.d
- Number of digits after the decimal.public void print(java.io.PrintWriter output, int w, int d)
print
in class AllMatrices
output
- Output stream.w
- Column width.d
- Number of digits after the decimal.public void print(java.text.NumberFormat format, int width)
print
in class AllMatrices
format
- A Formatting object for individual elements.width
- Field width for each column.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public void print(java.io.PrintWriter output, java.text.NumberFormat format, int width)
print
in class AllMatrices
output
- the output stream.format
- A formatting object to format the matrix elementswidth
- Column width.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public static JamaMatrix read(java.io.BufferedReader input) throws java.io.IOException
input
- the input stream.
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |