ru.sscc.matrix.solve
Class RealDirectSolver

java.lang.Object
  |
  +--ru.sscc.matrix.solve.RealDirectSolver
Direct Known Subclasses:
CholeskyBandSolver, RealDenseSolver

public abstract class RealDirectSolver
extends java.lang.Object
implements RealSolver, java.lang.Cloneable

Basic abstract class for all real direct solvers of SLAE. The direct solver provides two abstract methods: matrix factorization and solve. The iterative refinement of the solution and the matrix inversion are implemented in this class.

See Also:
Serialized Form

Constructor Summary
RealDirectSolver()
           
 
Method Summary
 java.lang.Object clone()
          Should return a clear clone of the solver without attached matrix.
 DenseMatrix constructInverse(DenseMatrix target)
          Constructs the inverse matrix with the help of the solve method.
 DenseMatrix constructRefinedInverse(RealMatrix matrix, DenseMatrix target)
          Constructs the inverse matrix with the help of the solveAndRefine method.
 void ensureFactorized()
          Tests the matrix to be already factorized and throws IllegalStateException if not.
abstract  RealDirectSolver factorize()
          Matrix factorization.
 boolean isFactorized()
          Returns the matrix factorization tag.
protected  void setFactorized(boolean factorized)
          Sets the factorization tag.
abstract  void solve(RealVector source, RealVector target)
          Solves SLAE using already factorized matrix.
 boolean solveAndRefine(RealMatrix matrix, RealVector source, RealVector target)
          Solves SLAE and refines the solution using the iterative refinement algorithm.
abstract  int sourceSize()
          Returns a size of right-hand side (rows number).
abstract  int targetSize()
          Returns a size of solution (columns number).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RealDirectSolver

public RealDirectSolver()
Method Detail

sourceSize

public abstract int sourceSize()
Returns a size of right-hand side (rows number).
Specified by:
sourceSize in interface RealSolver

targetSize

public abstract int targetSize()
Returns a size of solution (columns number).
Specified by:
targetSize in interface RealSolver

isFactorized

public final boolean isFactorized()
Returns the matrix factorization tag.

setFactorized

protected final void setFactorized(boolean factorized)
Sets the factorization tag.

ensureFactorized

public final void ensureFactorized()
Tests the matrix to be already factorized and throws IllegalStateException if not.

clone

public java.lang.Object clone()
Should return a clear clone of the solver without attached matrix.
Overrides:
clone in class java.lang.Object

factorize

public abstract RealDirectSolver factorize()
                                    throws CalculatingException
Matrix factorization. Does nothing if the matrix is already factorized. For ill-posed matrix the method has to throw CalculatingException and set the factorization tag to true if the factorization was completed. For incorrect matrix this exception should be thrown also but without change of the factorization tag.
Returns:
itself
Throws:
CalculatingException - is thrown when the matrix is ill-posed or incorrect

solve

public abstract void solve(RealVector source,
                           RealVector target)
Solves SLAE using already factorized matrix. Should throw IllegalStateException if the matrix isn't factorized yet.
Specified by:
solve in interface RealSolver
Parameters:
source - a source vector (the right hand side of SLAE)
target - a target vector to write the solution

solveAndRefine

public boolean solveAndRefine(RealMatrix matrix,
                              RealVector source,
                              RealVector target)
Solves SLAE and refines the solution using the iterative refinement algorithm. To do the refinement, the initial non-factorized matrix is needed. Use the RealMatrix.clone() operation for this purpose before the factorization of the matrix. The iterative refinement can improve the accuracy of the result if the matrix-by-vector multiplication is produced with higher accuracy. For example, when the matrix and the vectors are presented as the float[] type vectors.
Parameters:
matrix - the initial matrix
source - a source vector (the right hand side of SLAE)
target - a target vector to write the solution
Returns:
true, if the refinement is effective

constructInverse

public DenseMatrix constructInverse(DenseMatrix target)
Constructs the inverse matrix with the help of the solve method. If the matrix was factorized with the help of a RealCommonSolver, the pseudo-inverse matrix will be constructed. The inverse matrix is stored in the target matrix. If target==null, the target matrix will be created.
Parameters:
target - the dense matrix to store the result (null is allowed)
Returns:
the inverse matrix (the target matrix if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if the solver isn't factorized or the target matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of the target matrix are incompatible

constructRefinedInverse

public DenseMatrix constructRefinedInverse(RealMatrix matrix,
                                           DenseMatrix target)
Constructs the inverse matrix with the help of the solveAndRefine method. To do the refinement, the initial non-factorized matrix is needed. If the matrix was factorized with the help of a RealCommonSolver, the pseudo-inverse matrix will be constructed. The inverse matrix is stored in the target matrix. If target==null, the target matrix will be created.
Parameters:
matrix - the initial matrix
target - the dense matrix to store the result (null is allowed)
Returns:
the inverse matrix (the target matrix if it isn't equal to null)
Throws:
java.lang.IllegalStateException - is thrown if the solver isn't factorized or the initial or target matrix isn't algebraic
java.lang.IllegalArgumentException - is thrown if the dimensions of the initial or target matrices are incompatible