public class IntegerMatrix
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of int 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:
int[][] vals = { { 1., 2., 3 }, { 4., 5., 6. }, { 7., 8., 10. } }; Matrix A = new Matrix(vals); Matrix b = Matrix.random( 3, 1); Matrix x = A.solve(b); Matrix r = A.times( x).minus( b); int rnorm = r.normInf();
Constructor and Description |
---|
IntegerMatrix(int[][] A)
Construct a matrix from a 2-D array.
|
IntegerMatrix(int[][] A,
int m,
int n)
Construct a matrix quickly without checking arguments.
|
IntegerMatrix(int[] vals,
int m)
Construct a matrix from a one-dimensional packed array
|
IntegerMatrix(int m,
int n)
Construct an m-by-n matrix of zeros.
|
IntegerMatrix(int m,
int n,
int s)
Construct an m-by-n constant matrix.
|
Modifier and Type | Method and Description |
---|---|
IntegerMatrix |
arrayLeftDivide(IntegerMatrix B)
Element-by-element left division, C = A.\B
|
IntegerMatrix |
arrayLeftDivideEquals(IntegerMatrix B)
Element-by-element left division in place, A = A.\B
|
IntegerMatrix |
arrayRightDivide(IntegerMatrix B)
Element-by-element right division, C = A./B
|
IntegerMatrix |
arrayRightDivideEquals(IntegerMatrix B)
Element-by-element right division in place, A = A./B
|
IntegerMatrix |
arrayTimes(IntegerMatrix B)
Element-by-element multiplication, C = A.*B
|
IntegerMatrix |
arrayTimesEquals(IntegerMatrix B)
Element-by-element multiplication in place, A = A.*B
|
java.lang.Object |
clone()
Clone the Matrix object.
|
static IntegerMatrix |
constructWithCopy(int[][] A)
Construct a matrix from a copy of a 2-D array.
|
IntegerMatrix |
copy()
Make a deep copy of a matrix
|
boolean |
equals(java.lang.Object obj) |
int |
get(int i,
int j)
Get a single element.
|
int[][] |
getArray()
Access the internal two-dimensional array.
|
int[][] |
getArrayCopy()
Copy the internal two-dimensional array.
|
int |
getColumnDimension()
Get column dimension.
|
int[] |
getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array.
|
IntegerMatrix |
getMatrix(int[] r,
int[] c)
Get a submatrix.
|
IntegerMatrix |
getMatrix(int[] r,
int j0,
int j1)
Get a submatrix.
|
IntegerMatrix |
getMatrix(int i0,
int i1,
int[] c)
Get a submatrix.
|
IntegerMatrix |
getMatrix(int i0,
int i1,
int j0,
int j1)
Get a submatrix.
|
int |
getRowDimension()
Get row dimension.
|
int[] |
getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array.
|
IntegerMatrix |
howell(int N)
Return the Howell form of this Matrix, Modulo N
|
static IntegerMatrix |
identity(int m,
int n)
Generate identity matrix
|
IntegerMatrix |
minus(IntegerMatrix B)
C = A - B
|
IntegerMatrix |
minusEquals(IntegerMatrix B)
A = A - B
|
int |
norm1()
One norm
|
int |
normF()
Frobenius norm
|
int |
normInf()
Infinity norm
|
IntegerMatrix |
plus(IntegerMatrix B)
C = A + B
|
IntegerMatrix |
plusEquals(IntegerMatrix 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.
|
static IntegerMatrix |
random(int m,
int n)
Generate matrix with random elements
|
static IntegerMatrix |
read(java.io.BufferedReader input)
Read a matrix from a stream.
|
void |
set(int i,
int j,
int s)
Set a single element.
|
void |
setMatrix(int[] r,
int[] c,
IntegerMatrix X)
Set a submatrix.
|
void |
setMatrix(int[] r,
int j0,
int j1,
IntegerMatrix X)
Set a submatrix.
|
void |
setMatrix(int i0,
int i1,
int[] c,
IntegerMatrix X)
Set a submatrix.
|
void |
setMatrix(int i0,
int i1,
int j0,
int j1,
IntegerMatrix X)
Set a submatrix.
|
IntegerMatrix |
times(int s)
Multiply a matrix by a scalar, C = s*A
|
IntegerMatrix |
times(IntegerMatrix B)
Linear algebraic matrix multiplication, A * B
|
IntegerMatrix |
timesEquals(int s)
Multiply a matrix by a scalar in place, A = s*A
|
java.lang.String |
toHTMLString() |
java.lang.String |
toString() |
int |
trace()
Matrix trace.
|
IntegerMatrix |
transpose()
Matrix transpose.
|
IntegerMatrix |
uminus()
Unary minus
|
public IntegerMatrix(int m, int n)
m
- Number of rows.n
- Number of colums.public IntegerMatrix(int m, int n, int s)
m
- Number of rows.n
- Number of colums.s
- Fill the matrix with this scalar value.public IntegerMatrix(int[][] A)
A
- Two-dimensional array of ints.java.lang.IllegalArgumentException
- All rows must have the same lengthconstructWithCopy(int[][])
public IntegerMatrix(int[][] A, int m, int n)
A
- Two-dimensional array of ints.m
- Number of rows.n
- Number of colums.public IntegerMatrix(int[] vals, int m)
vals
- One-dimensional array of ints, packed by columns (ala Fortran).m
- Number of rows.java.lang.IllegalArgumentException
- Array length must be a multiple of m.public static IntegerMatrix constructWithCopy(int[][] A)
A
- Two-dimensional array of ints.java.lang.IllegalArgumentException
- All rows must have the same lengthpublic IntegerMatrix copy()
public java.lang.Object clone()
clone
in class java.lang.Object
public int[][] getArray()
public int[][] getArrayCopy()
public int[] getColumnPackedCopy()
public int[] getRowPackedCopy()
public int getRowDimension()
public int getColumnDimension()
public int get(int i, int j)
i
- Row index.j
- Column index.java.lang.ArrayIndexOutOfBoundsException
public IntegerMatrix getMatrix(int i0, int i1, int j0, int j1)
i0
- Initial row indexi1
- Final row indexj0
- Initial column indexj1
- Final column indexjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic IntegerMatrix getMatrix(int[] r, int[] c)
r
- Array of row indices.c
- Array of column indices.java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic IntegerMatrix getMatrix(int i0, int i1, int[] c)
i0
- Initial row indexi1
- Final row indexc
- Array of column indices.java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic IntegerMatrix getMatrix(int[] r, int j0, int j1)
r
- Array of row indices.i0
- Initial column indexi1
- Final column indexjava.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic void set(int i, int j, int s)
i
- Row index.j
- Column index.s
- A(i,j).java.lang.ArrayIndexOutOfBoundsException
public void setMatrix(int i0, int i1, int j0, int j1, IntegerMatrix 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, IntegerMatrix 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, IntegerMatrix 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, IntegerMatrix X)
i0
- Initial row indexi1
- Final row indexc
- Array of column indices.X
- A(i0:i1,c(:))java.lang.ArrayIndexOutOfBoundsException
- Submatrix indicespublic IntegerMatrix transpose()
public int norm1()
public int normInf()
public int normF()
public IntegerMatrix uminus()
public IntegerMatrix plus(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix plusEquals(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix minus(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix minusEquals(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayTimes(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayTimesEquals(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayRightDivide(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayRightDivideEquals(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayLeftDivide(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix arrayLeftDivideEquals(IntegerMatrix B)
B
- another matrixpublic IntegerMatrix times(int s)
s
- scalarpublic IntegerMatrix timesEquals(int s)
s
- scalarpublic IntegerMatrix times(IntegerMatrix B)
B
- another matrixjava.lang.IllegalArgumentException
- Matrix inner dimensions must agree.public int trace()
public static IntegerMatrix random(int m, int n)
m
- Number of rows.n
- Number of colums.public static IntegerMatrix identity(int m, int n)
m
- Number of rows.n
- Number of colums.public void print(int w, int d)
w
- Column width.d
- Number of digits after the decimal.public void print(java.io.PrintWriter output, int w, int d)
output
- Output stream.w
- Column width.d
- Number of digits after the decimal.public void print(java.text.NumberFormat format, int width)
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)
output
- the output stream.format
- A formatting object to format the matrix elementswidth
- Column width.DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)
public static IntegerMatrix read(java.io.BufferedReader input) throws java.io.IOException
input
- the input stream.java.io.IOException
public IntegerMatrix howell(int N)
N
- public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toHTMLString()