corina.index
Class Solver
java.lang.Object
|
+--corina.index.Solver
- public class Solver
- extends Object
A collection of matrix solvers.
solveNxN
will solve any square matrix system. In
solving Ax=b, it will destroy A (and b?). The
routines were adapted from chapter 6 of Introduction to
Scientific Computing, second edition, Charles van Loan. The
solver uses LU decomposition with pivoting.
Also contains a least-squares fitter,
leastSquares()
, from Introduction to
Algorithms, Cormen, Leiserson, and Rivest, pp. 768-771, which
uses the matrix solvers.
- Version:
- $Id: Solver.java,v 1.1.1.1 2002/04/11 19:40:21 bitpoet Exp $
- Author:
- Ken Harris
Method Summary |
static double[] |
leastSquares(Solver.Solveable s,
double[] x,
double[] y)
A least-squares solver. |
static double[] |
solve2x2(double[][] A,
double[] b)
A special case of solveNxN for 2x2 matrices. |
static double[] |
solveNxN(double[][] A,
double[] b)
Solve the general equation Ax=b for x, given square matrix A
and vector b. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Solver
public Solver()
solveNxN
public static double[] solveNxN(double[][] A,
double[] b)
throws Solver.SingularMatrixException
- Solve the general equation Ax=b for x, given square matrix A
and vector b. (Intended to be partially compatible with
Numerical Recipes'
gaussj
, which it replaces.)
See van Loan for derivation.
- Parameters:
A
- the "A" matrix in Ax=bb
- the "b" matrix in Ax=b; it is replaced with x- Throws:
IllegalArgumentException
- if A is not square, or b
is a different sizeSolver.SingularMatrixException
- if A is singular
solve2x2
public static double[] solve2x2(double[][] A,
double[] b)
throws Solver.SingularMatrixException
- A special case of
solveNxN
for 2x2 matrices. In
the equation Ax=b, given A and b, x is found; its value is
written back into b. Direct substitution is used, so it is
very fast (only 10 floating-point operations).
- Parameters:
A
- the "A" matrix in Ax=b; it is untouchedb
- the "b" matrix in Ax=b; it is replaced with x- Throws:
IllegalArgumentException
- if A is any size other
than 2x2 or b is any size other than 2Solver.SingularMatrixException
- if A is singular
leastSquares
public static double[] leastSquares(Solver.Solveable s,
double[] x,
double[] y)
throws Solver.SingularMatrixException
- A least-squares solver. See Introduction to
Algorithms, Cormen, Leiserson, and Rivest, pp. 768-771.
This uses
solveNxN
or solve2x2
.
- Parameters:
s
- an object that can evaluate the basis functionsx
- the x-coordinates of the datay
- the y-coordinates of the data- Returns:
- the coefficients of the basis functions
- Throws:
Solver.SingularMatrixException
- (can this happen?)