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.

Version:
2.2
Author:
Mark Hale

Method Summary
static double[] eigenSolveHermitian(ComplexSquareMatrix matrix, ComplexVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a Hermitian matrix.
static double[] eigenSolveSymmetric(DoubleSquareMatrix matrix, DoubleVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a symmetric square matrix.
static double[] eigenSolveSymmetric(DoubleTridiagonalMatrix matrix, DoubleVector[] eigenvector)
          This method finds the eigenvalues and eigenvectors of a symmetric tridiagonal matrix by the QL method.
static double[] eigenvalueSolveHermitian(ComplexSquareMatrix matrix)
          This method finds the eigenvalues of a Hermitian matrix.
static double[] eigenvalueSolveSymmetric(DoubleSquareMatrix matrix)
          This method finds the eigenvalues of a symmetric square matrix.
static double[] eigenvalueSolveSymmetric(DoubleTridiagonalMatrix matrix)
          This method finds the eigenvalues of a symmetric tridiagonal matrix by the QL method.
static DoubleVector leastSquaresFit(int n, double[][] data)
          Fits an nth degree polynomial to data using the method of least squares.
static DoubleVector linearRegression(double[][] data)
          Fits a line to multi-dimensional data using the method of least squares.
static DoubleVector[] orthonormalize(DoubleVector[] vecs)
          The Gram-Schmidt orthonormalization method.
static DoubleVector solve(DoubleSquareMatrix M, DoubleVector v)
          Solves the linear system Mx=v.
static DoubleVector solveGMRes(DoubleMatrix A, DoubleVector 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 DoubleVector solve(DoubleSquareMatrix M,
                                 DoubleVector 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 DoubleVector solveGMRes(DoubleMatrix A,
                                      DoubleVector 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 DoubleVector 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.
data - [0][] contains the x-series, [1][] contains the y-series.
Returns:
a vector containing the polynomial's coefficients (in ascending degree order).

linearRegression

public static DoubleVector 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.

orthonormalize

public static DoubleVector[] orthonormalize(DoubleVector[] 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(ComplexSquareMatrix 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 more than 50 iterations to determine an eigenvalue.

eigenSolveHermitian

public static double[] eigenSolveHermitian(ComplexSquareMatrix matrix,
                                           ComplexVector[] 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 more than 50 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 more than 50 iterations to determine an eigenvalue.

eigenSolveSymmetric

public static double[] eigenSolveSymmetric(DoubleTridiagonalMatrix matrix,
                                           DoubleVector[] 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 more than 50 iterations to determine an eigenvalue.

eigenvalueSolveSymmetric

public static double[] eigenvalueSolveSymmetric(DoubleSquareMatrix 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 more than 50 iterations to determine an eigenvalue.

eigenSolveSymmetric

public static double[] eigenSolveSymmetric(DoubleSquareMatrix matrix,
                                           DoubleVector[] 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 more than 50 iterations to determine an eigenvalue.