public class Matrix extends Object implements IMatrix
Matrices are a key tool in linear algebra. One use of matrices is to represent linear transformations and matrix multiplication corresponds to composition of linear transformations. Matrices can also keep track of the coefficients in a system of linear equations. For a square matrix, the determinant and inverse matrix (when it exists) govern the behavior of solutions to the corresponding system of linear equations, and eigenvalues and eigenvectors provide insight into the geometry of the associated linear transformation.
There are several methods to render matrices into a more easily accessible form. They are generally referred to as matrix transformation or matrix decomposition techniques. The interest of all these decomposition techniques is that they preserve certain properties of the matrices in question, such as determinant, rank or inverse, so that these quantities can be calculated after applying the transformation, or that certain matrix operations are algorithmically easier to carry out for some types of matrices.
The LU decomposition factors matrices as a product of lower (L) and an upper triangular matrices (U). Once this decomposition is calculated, linear systems can be solved more efficiently, by a simple technique called forward and back substitution. Likewise, inverses of triangular matrices are algorithmically easier to calculate. The QR decomposition factors matrices as a product of an orthogonal (Q) and a right triangular matrix (R). QR decomposition is often used to solve the linear least squares problem, and is the basis for a particular eigenvalue algorithm, the QR algorithm. Singular value decomposition expresses any matrix A as a product UDV', where U and V are unitary matrices and D is a diagonal matrix. The eigendecomposition or diagonalization expresses A as a product VDV-1, where D is a diagonal matrix and V is a suitable invertible matrix. If A can be written in this form, it is called diagonalizable.
| Constructor and Description |
|---|
Matrix(double[][] A)
Constructor.
|
Matrix(double[][] A,
boolean symmetric)
Constructor.
|
Matrix(double[][] A,
boolean symmetric,
boolean positive)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
asolve(double[] b,
double[] x)
Solve Ad * x = b for the preconditioner matrix Ad.
|
void |
atx(double[] x,
double[] y)
y = A' * x
|
void |
atxpy(double[] x,
double[] y)
y = A' * x + y
|
void |
atxpy(double[] x,
double[] y,
double b)
y = A' * x + b * y
|
void |
ax(double[] x,
double[] y)
y = A * x
|
void |
axpy(double[] x,
double[] y)
y = A * x + y
|
void |
axpy(double[] x,
double[] y,
double b)
y = A * x + b * y
|
CholeskyDecomposition |
cholesky()
Returns the Cholesky decomposition.
|
double |
det()
Returns the matrix determinant.
|
EigenValueDecomposition |
eigen()
Returns the eigen value decomposition.
|
double |
eigen(double[] v)
Returns the largest eigen pair of matrix with the power iteration
under the assumptions A has an eigenvalue that is strictly greater
in magnitude than its other eigenvalues and the starting
vector has a nonzero component in the direction of an eigenvector
associated with the dominant eigenvalue.
|
EigenValueDecomposition |
eigen(int k)
Returns the k largest eigen pairs.
|
double |
get(int i,
int j)
Returns the entry value at row i and column j.
|
void |
improve(double[] b,
double[] x)
Iteratively improve a solution to linear equations.
|
double[][] |
inverse()
Returns the matrix inverse or pseudo inverse.
|
LUDecomposition |
LU()
Returns the LU decomposition.
|
int |
ncols()
Returns the number of columns.
|
int |
nrows()
Returns the number of rows.
|
QRDecomposition |
QR()
Returns the QR decomposition.
|
int |
rank()
Returns the matrix rank.
|
void |
set(int i,
int j,
double x)
Set the entry value at row i and column j.
|
double[] |
solve(double[] b)
Solve A*x = b in place (exact solution if A is square, least squares
solution otherwise), which means the results will be stored in b.
|
double[][] |
solve(double[][] B)
Solve A*X = B in place (exact solution if A is square, least squares
solution otherwise), which means the results will be stored in B.
|
SingularValueDecomposition |
svd()
Returns the singular value decomposition.
|
double |
trace()
Returns the matrix trace.
|
Matrix |
transpose()
Returns the matrix transpose.
|
public Matrix(double[][] A)
A - the array of matrix.public Matrix(double[][] A,
boolean symmetric)
A - the array of matrix.symmetric - true if the matrix is symmetric.public Matrix(double[][] A,
boolean symmetric,
boolean positive)
A - the array of matrix.symmetric - true if the matrix is symmetric.positive - true if the matrix is positive definite.public int nrows()
IMatrixpublic int ncols()
IMatrixpublic double get(int i,
int j)
IMatrixpublic void set(int i,
int j,
double x)
IMatrixpublic void ax(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y)
IMatrixpublic void axpy(double[] x,
double[] y,
double b)
IMatrixpublic void atx(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y)
IMatrixpublic void atxpy(double[] x,
double[] y,
double b)
IMatrixpublic void asolve(double[] b,
double[] x)
IMatrixpublic Matrix transpose()
public double[][] inverse()
public double trace()
public double det()
public int rank()
public double eigen(double[] v)
v - on input, it is the non-zero initial guess of the eigen vector.
On output, it is the eigen vector corresponding largest eigen value.public EigenValueDecomposition eigen()
public EigenValueDecomposition eigen(int k)
public SingularValueDecomposition svd()
public LUDecomposition LU()
public CholeskyDecomposition cholesky()
public QRDecomposition QR()
public double[] solve(double[] b)
public double[][] solve(double[][] B)
public void improve(double[] b,
double[] x)
b - right hand side of linear equations.x - a solution to linear equations.Copyright © 2015. All rights reserved.