public class DMatrix
extends java.lang.Object
a[0] a[3] a[6]
a[1] a[4] a[7]
a[2] a[5] a[8]
This is the column-major order required by LAPACK.
Decompositions of a matrix A facilate the solutions of various problems. For example, the QR decomposition A = Q*R of a rectangular matrix A (where Q is orthogonal and R is upper right triangular) is useful in least-square approximations. Decompositions currently provided by this class include
Constructor and Description |
---|
DMatrix(DMatrix a)
Constructs a copy of the specified matrix.
|
DMatrix(double[][] a)
Constructs a matrix from the specified array.
|
DMatrix(int m,
int n)
Constructs an m-by-n matrix of zeros.
|
DMatrix(int m,
int n,
double v)
Constructs an m-by-n matrix filled with the specified value.
|
DMatrix(int m,
int n,
double[] a)
Constructs a matrix from the specified array.
|
Modifier and Type | Method and Description |
---|---|
DMatrix |
arrayLeftDivide(DMatrix b)
Returns C = A .\ B, where A is this matrix.
|
DMatrix |
arrayLeftDivideEquals(DMatrix b)
Returns A = A .\ B, where A is this matrix.
|
DMatrix |
arrayRightDivide(DMatrix b)
Returns C = A ./ B, where A is this matrix.
|
DMatrix |
arrayRightDivideEquals(DMatrix b)
Returns A = A ./ B, where A is this matrix.
|
DMatrix |
arrayTimes(DMatrix b)
Returns C = A .* B, where A is this matrix.
|
DMatrix |
arrayTimesEquals(DMatrix b)
Returns A = A .* B, where A is this matrix.
|
DMatrixChd |
chd()
Returns the Cholesky decomposition of this matrix.
|
double |
cond()
Returns the condition number of this matrix.
|
double |
det()
Returns the determinant of this matrix.
|
static DMatrix |
diagonal(double[] d)
Returns a new diagonal matrix with specified elements.
|
boolean |
equals(java.lang.Object obj) |
DMatrixEvd |
evd()
Returns the eigenvalue and eigenvector decomposition of this matrix.
|
double[][] |
get()
Gets all elements of this matrix into a new array.
|
void |
get(double[][] a)
Gets all elements of this matrix into the specified array.
|
DMatrix |
get(int[] r,
int j)
Gets a matrix from specified rows and one column of this matrix.
|
DMatrix |
get(int[] r,
int[] c)
Gets a new matrix from the specified rows and columns of this matrix.
|
DMatrix |
get(int[] r,
int j0,
int j1)
Gets a matrix from specified rows and columns of this matrix.
|
double |
get(int i,
int j)
Gets a matrix element.
|
DMatrix |
get(int i,
int[] c)
Gets a matrix from specified one row and columns of this matrix.
|
DMatrix |
get(int i0,
int i1,
int[] c)
Gets a matrix from specified rows and columns of this matrix.
|
DMatrix |
get(int i0,
int i1,
int j0,
int j1)
Gets the specified submatrix a[i0:i1][j0:j1] of this matrix.
|
double[] |
getArray()
Gets the array in which matrix elements are stored.
|
int |
getColumnCount()
Gets the number of columns in this matrix.
|
int |
getM()
Gets the number of rows in this matrix.
|
int |
getN()
Gets the number of columns in this matrix.
|
double[] |
getPackedColumns()
Gets the elements of this matrix packed by columns.
|
double[] |
getPackedRows()
Gets the elements of this matrix packed by rows.
|
int |
getRowCount()
Gets the number of rows in this matrix.
|
int |
hashCode() |
static DMatrix |
identity(int n)
Returns a new square identity matrix.
|
static DMatrix |
identity(int m,
int n)
Returns a new identity matrix.
|
DMatrix |
inverse()
Returns the inverse of this matrix.
|
boolean |
isSquare()
Determines whether this matrix is square.
|
boolean |
isSymmetric()
Determines whether this matrix is symmetric (and square).
|
DMatrixLud |
lud()
Returns the LU decomposition of this matrix.
|
DMatrix |
minus(DMatrix b)
Returns C = A - B, where A is this matrix.
|
DMatrix |
minusEquals(DMatrix b)
Returns A = A - B, where A is this matrix.
|
DMatrix |
negate()
Returns C = -A, where A is this matrix.
|
double |
norm1()
Returns the one-norm (maximum column sum) of this matrix.
|
double |
norm2()
Returns the two-norm (maximum singular value) of this matrix.
|
double |
normF()
Returns the Frobenius norm (sqrt of sum of squares) of this matrix.
|
double |
normI()
Returns the infinity-norm (maximum row sum) of this matrix.
|
DMatrix |
plus(DMatrix b)
Returns C = A + B, where A is this matrix.
|
DMatrix |
plusEquals(DMatrix b)
Returns A = A + B, where A is this matrix.
|
DMatrixQrd |
qrd()
Returns the QR decomposition of this matrix.
|
static DMatrix |
random(int n)
Returns a new square matrix with random elements.
|
static DMatrix |
random(int m,
int n)
Returns a new matrix with random elements.
|
double |
rank()
Returns the effective numerical rank of this matrix.
|
void |
set(double[][] a)
Sets all elements of this matrix from the specified array.
|
void |
set(int[] r,
int[] c,
DMatrix x)
Sets the specified rows and columns of this matrix.
|
void |
set(int[] r,
int j,
DMatrix x)
Sets the specified rows and one column of this matrix.
|
void |
set(int[] r,
int j0,
int j1,
DMatrix x)
Sets the specified rows and columns of this matrix.
|
void |
set(int i,
int[] c,
DMatrix x)
Sets the specified one row and columns of this matrix.
|
void |
set(int i,
int j,
double v)
Sets a matrix element.
|
void |
set(int i0,
int i1,
int[] c,
DMatrix x)
Sets the specified rows and columns of this matrix.
|
void |
set(int i0,
int i1,
int j0,
int j1,
DMatrix x)
Sets the specified submatrix a[i0:i1][j0:j1] of this matrix.
|
void |
setPackedColumns(double[] c)
Sets the elements of this matrix from an array packed by columns.
|
void |
setPackedRows(double[] r)
Sets the elements of this matrix from an array packed by rows.
|
DMatrix |
solve(DMatrix b)
Solves the system A*X = B.
|
DMatrixSvd |
svd()
Returns the singular value decomposition of this matrix.
|
DMatrix |
times(DMatrix b)
Returns C = A * B, where A is this matrix.
|
DMatrix |
times(double s)
Returns C = A * s, where A is this matrix, and s is a scalar.
|
DMatrix |
timesEquals(double s)
Returns A = A * s, where A is this matrix, and s is a scalar.
|
DMatrix |
timesTranspose(DMatrix b)
Returns C = A * B', where A is this matrix and B' is B transposed.
|
java.lang.String |
toString() |
double |
trace()
Returns the trace (sum of diagonal elements) of this matrix.
|
DMatrix |
transpose()
Returns the transpose of this matrix.
|
DMatrix |
transposeTimes(DMatrix b)
Returns C = A' * B, where A' is this matrix transposed.
|
public DMatrix(int m, int n)
m
- the number of rows.n
- the number of columns.public DMatrix(int m, int n, double v)
m
- the number of rows.n
- the number of columns.v
- the value.public DMatrix(int m, int n, double[] a)
That array contains packed columns of this matrix. In other words, array element a[i+j*m] corresponds to the i'th row and j'th column of this matrix.
m
- the number of rows.n
- the number of columns.a
- the array.public DMatrix(double[][] a)
The specified array must be regular. That is, each row much contain the same number of columns, and each column must contain the same number of rows.
a
- the array.public DMatrix(DMatrix a)
a
- the matrix.public int getM()
public int getRowCount()
public int getN()
public int getColumnCount()
public double[] getArray()
public boolean isSquare()
public boolean isSymmetric()
public double[][] get()
public void get(double[][] a)
a
- the array.public double get(int i, int j)
i
- the row index.j
- the column index.public DMatrix get(int i0, int i1, int j0, int j1)
i0
- the index of first row.i1
- the index of last row.j0
- the index of first column.j1
- the index of last column.public DMatrix get(int[] r, int[] c)
r
- the array of row indices; null, for all rows.c
- the array of column indices; null, for all columns.public DMatrix get(int i, int[] c)
i
- the row index.c
- the array of column indices; null, for all columns.public DMatrix get(int[] r, int j)
r
- the array of row indices; null, for all rows.j
- the column index.public DMatrix get(int i0, int i1, int[] c)
i0
- the index of the first row.i1
- the index of the last row.c
- the array of column indices; null, for all columns.public DMatrix get(int[] r, int j0, int j1)
r
- the array of row indices; null, for all rows.j0
- the index of the first column.j1
- the index of the last column.public double[] getPackedColumns()
public double[] getPackedRows()
public void set(double[][] a)
a
- the array.public void set(int i, int j, double v)
i
- the row index.j
- the column index.v
- the element value.public void set(int i0, int i1, int j0, int j1, DMatrix x)
i0
- the index of first row.i1
- the index of last row.j0
- the index of first column.j1
- the index of last column.x
- the matrix from which to copy elements.public void set(int[] r, int[] c, DMatrix x)
r
- the array of row indices; null, for all rows.c
- the array of column indices; null, for all columns.x
- the matrix from which to copy elements.public void set(int i, int[] c, DMatrix x)
i
- the row index.c
- the array of column indices; null, for all columns.x
- the matrix from which to copy elements.public void set(int[] r, int j, DMatrix x)
r
- the array of row indices; null, for all rows.j
- the column index.x
- the matrix from which to copy elements.public void set(int i0, int i1, int[] c, DMatrix x)
i0
- the index of the first row.i1
- the index of the last row.c
- the array of column indices; null, for all columns.x
- the matrix from which to copy elements.public void set(int[] r, int j0, int j1, DMatrix x)
r
- the array of row indices; null, for all rows.j0
- the index of the first column.j1
- the index of the last column.x
- the matrix from which to copy elements.public void setPackedColumns(double[] c)
c
- the array of matrix elements packed by columns.public void setPackedRows(double[] r)
r
- the array of matrix elements packed by rows.public DMatrix transpose()
public double norm1()
public double norm2()
DMatrixSvd
public double normI()
public double normF()
public double det()
public double cond()
DMatrixSvd
public double rank()
DMatrixSvd
public double trace()
public DMatrixLud lud()
public DMatrixQrd qrd()
public DMatrixChd chd()
public DMatrixEvd evd()
public DMatrixSvd svd()
public DMatrix solve(DMatrix b)
b
- the matrix B of right-hand-side column vectors.public DMatrix inverse()
public DMatrix negate()
public DMatrix plus(DMatrix b)
b
- the matrix B.public DMatrix plusEquals(DMatrix b)
b
- the matrix B.public DMatrix minus(DMatrix b)
b
- the matrix B.public DMatrix minusEquals(DMatrix b)
b
- the matrix B.public DMatrix arrayTimes(DMatrix b)
b
- the matrix B.public DMatrix arrayTimesEquals(DMatrix b)
b
- the matrix B.public DMatrix arrayRightDivide(DMatrix b)
b
- the matrix B.public DMatrix arrayRightDivideEquals(DMatrix b)
b
- the matrix B.public DMatrix arrayLeftDivide(DMatrix b)
b
- the matrix B.public DMatrix arrayLeftDivideEquals(DMatrix b)
b
- the matrix B.public DMatrix times(double s)
s
- the scalar s.public DMatrix timesEquals(double s)
s
- the scalar s.public DMatrix times(DMatrix b)
b
- the matrix B.public DMatrix timesTranspose(DMatrix b)
b
- the matrix B.public DMatrix transposeTimes(DMatrix b)
b
- the matrix B.public static DMatrix random(int m, int n)
m
- the number of rows.n
- the number of columns.public static DMatrix random(int n)
n
- the number of rows and columns.public static DMatrix identity(int m, int n)
m
- the number of rows.n
- the number of columns.public static DMatrix identity(int n)
n
- the number of rows and columns.public static DMatrix diagonal(double[] d)
d
- array of diagonal elements d[k] = A(k,k).public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object