JSci.maths
Class LinearMath

java.lang.Object
  extended by JSci.maths.AbstractMath
      extended by JSci.maths.LinearMath

public final class LinearMath
extends AbstractMath

The linear math library. This class cannot be subclassed or instantiated because all methods are static.


Method Summary
static void diagonalizeSymmetric(AbstractDoubleSquareMatrix matrix)
          Diagonalizes a symmetric matrix in-place.
static double[] eigenSolveHermitian(AbstractComplexSquareMatrix matrix, AbstractComplexVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a Hermitian matrix.
static double[] eigenSolveSymmetric(AbstractDoubleSquareMatrix matrix, AbstractDoubleVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a symmetric square matrix.
static double[] eigenSolveSymmetric(DoubleTridiagonalMatrix matrix, AbstractDoubleVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix by the QL method.
static double[] eigenvalueSolveHermitian(AbstractComplexSquareMatrix matrix)
          This method finds the eigenvalues of a Hermitian matrix.
static double[] eigenvalueSolveSymmetric(AbstractDoubleSquareMatrix matrix)
          This method finds the eigenvalues of a symmetric square matrix.
static double[] eigenvalueSolveSymmetric(AbstractDoubleSquareMatrix matrix, AbstractDoubleVector initial, int iters)
          Finds the eigenvalues of a symmetric square matrix using the Lanczos method (with full reorthogonalization).
static double[] eigenvalueSolveSymmetric(DoubleTridiagonalMatrix matrix)
          This method finds the eigenvalues of a symmetric tridiagonal matrix by the QL method.
static RealPolynomial leastSquaresFit(int n, double[][] data)
          Fits an nth degree polynomial to data using the method of least squares.
static AbstractDoubleVector linearRegression(double[][] data)
          Fits a line to multi-dimensional data using the method of least squares.
static AbstractDoubleVector[] orthonormalize(AbstractDoubleVector[] vecs)
          The Gram-Schmidt orthonormalization method.
static AbstractDoubleVector solve(AbstractDoubleSquareMatrix M, AbstractDoubleVector v)
          Solves the linear system Mx=v.
static AbstractDoubleVector solveGMRes(AbstractDoubleMatrix A, AbstractDoubleVector b, int max_iter, double tol)
          Solves the unsymmetric linear system Ax=b using the Generalized Minimum Residual method (doesn't require A to be nonsingular).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

solve

public static AbstractDoubleVector solve(AbstractDoubleSquareMatrix M,
                                         AbstractDoubleVector v)
Solves the linear system Mx=v.

Parameters:
M - a double square matrix.
v - a double vector.
Returns:
the double vector x.

solveGMRes

public static AbstractDoubleVector solveGMRes(AbstractDoubleMatrix A,
                                              AbstractDoubleVector b,
                                              int max_iter,
                                              double tol)
                                       throws MaximumIterationsExceededException
Solves the unsymmetric linear system Ax=b using the Generalized Minimum Residual method (doesn't require A to be nonsingular). While slower than LU decomposition, it is more robust and should be used with large matrices. It is guaranted to converge exactly in N iterations for an N by N matrix (minus some numerical errors).

Parameters:
max_iter - maximum number of iterations.
tol - tolerance.
Throws:
java.lang.IllegalArgumentException - If either the tolerance or the number of iterations is not positive. Also, if an unexpected error occurs.
MaximumIterationsExceededException - If it cannot converge according to the given parameters.

leastSquaresFit

public static RealPolynomial leastSquaresFit(int n,
                                             double[][] data)
Fits an nth degree polynomial to data using the method of least squares.

Parameters:
n - the degree of the polynomial (>= 0).
data - [0][] contains the x-series, [1][] contains the y-series.

linearRegression

public static AbstractDoubleVector linearRegression(double[][] data)
Fits a line to multi-dimensional data using the method of least squares.

Parameters:
data - [0...n-1][] contains the x-series' (they must be linearly uncorrelated), [n][] contains the y-series.
Returns:
a vector containing the coefficients (zero component is the intercept, the rest are gradient components). E.g. y(x1, x2, ...) = coeffs(0) + coeffs(1) * x1 + coeffs(2) * x2 + ...

orthonormalize

public static AbstractDoubleVector[] orthonormalize(AbstractDoubleVector[] vecs)
The Gram-Schmidt orthonormalization method.

Parameters:
vecs - a set of linearly independent vectors.
Returns:
a set of orthonormal vectors.

eigenvalueSolveHermitian

public static double[] eigenvalueSolveHermitian(AbstractComplexSquareMatrix matrix)
                                         throws MaximumIterationsExceededException
This method finds the eigenvalues of a Hermitian matrix.

Parameters:
matrix - a Hermitian matrix.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

eigenSolveHermitian

public static double[] eigenSolveHermitian(AbstractComplexSquareMatrix matrix,
                                           AbstractComplexVector[] eigenvector)
                                    throws MaximumIterationsExceededException
This method finds the eigenvalues and eigenvectors of a Hermitian matrix.

Parameters:
matrix - a Hermitian matrix.
eigenvector - an empty array of complex vectors to hold the eigenvectors. All eigenvectors will be orthogonal.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

eigenvalueSolveSymmetric

public static double[] eigenvalueSolveSymmetric(DoubleTridiagonalMatrix matrix)
                                         throws MaximumIterationsExceededException
This method finds the eigenvalues of a symmetric tridiagonal matrix by the QL method. It is based on the NETLIB algol/fortran procedure tql1 by Bowdler, Martin, Reinsch and Wilkinson.

Parameters:
matrix - a double symmetric tridiagonal matrix.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

eigenSolveSymmetric

public static double[] eigenSolveSymmetric(DoubleTridiagonalMatrix matrix,
                                           AbstractDoubleVector[] eigenvector)
                                    throws MaximumIterationsExceededException
This method finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix by the QL method. It is based on the NETLIB algol/fortran procedure tql2 by Bowdler, Martin, Reinsch and Wilkinson.

Parameters:
matrix - a double symmetric tridiagonal matrix.
eigenvector - an empty array of double vectors to hold the eigenvectors. All eigenvectors will be orthogonal.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

eigenvalueSolveSymmetric

public static double[] eigenvalueSolveSymmetric(AbstractDoubleSquareMatrix matrix)
                                         throws MaximumIterationsExceededException
This method finds the eigenvalues of a symmetric square matrix. The matrix is reduced to tridiagonal form and then the QL method is applied. It is based on the NETLIB algol/fortran procedure tred1/tql1 by Bowdler, Martin, Reinsch and Wilkinson.

Parameters:
matrix - a double symmetric square matrix.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

eigenSolveSymmetric

public static double[] eigenSolveSymmetric(AbstractDoubleSquareMatrix matrix,
                                           AbstractDoubleVector[] eigenvector)
                                    throws MaximumIterationsExceededException
This method finds the eigenvalues and eigenvectors of a symmetric square matrix. The matrix is reduced to tridiagonal form and then the QL method is applied. It is based on the NETLIB algol/fortran procedure tred2/tql2 by Bowdler, Martin, Reinsch and Wilkinson.

Parameters:
matrix - a double symmetric square matrix.
eigenvector - an empty array of double vectors to hold the eigenvectors. All eigenvectors will be orthogonal.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException - If it takes too many iterations to determine an eigenvalue.

diagonalizeSymmetric

public static void diagonalizeSymmetric(AbstractDoubleSquareMatrix matrix)
                                 throws MaximumIterationsExceededException
Diagonalizes a symmetric matrix in-place. Memory conservative method for finding the eigenvalues of a (large) symmetric matrix.

Parameters:
matrix - a double symmetric square matrix.
Throws:
MaximumIterationsExceededException

eigenvalueSolveSymmetric

public static double[] eigenvalueSolveSymmetric(AbstractDoubleSquareMatrix matrix,
                                                AbstractDoubleVector initial,
                                                int iters)
                                         throws MaximumIterationsExceededException
Finds the eigenvalues of a symmetric square matrix using the Lanczos method (with full reorthogonalization).

Parameters:
matrix - a symmetric square matrix
initial - initial starting vector. Must be normalized.
iters - number of iterations.
Returns:
an array containing the eigenvalues.
Throws:
MaximumIterationsExceededException