Class GaussianElimination
- Object
-
- edu.princeton.cs.algs4.GaussianElimination
-
public class GaussianElimination extends Object
TheGaussianEliminationdata type provides methods to solve a linear system of equations Ax = b, where A is an m-by-n matrix and b is a length n vector.This is a bare-bones implementation that uses Gaussian elimination with partial pivoting. See GaussianEliminationLite.java for a stripped-down version that assumes the matrix A is square and nonsingular. See
GaussJordanEliminationfor an alternate implementation that uses Gauss-Jordan elimination. For an industrial-strength numerical linear algebra library, see JAMA.This computes correct results if all arithmetic performed is without floating-point rounding error or arithmetic overflow. In practice, there will be floating-point rounding error; partial pivoting helps prevent accumulated floating-point rounding errors from growing out of control (though it does not provide any guarantees).
For additional documentation, see Section 9.9 Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
-
-
Constructor Summary
Constructors Constructor Description GaussianElimination(double[][] A, double[] b)Solves the linear system of equations Ax = b, where A is an m-by-n matrix and b is a length m vector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisFeasible()Returns true if there exists a solution to the linear system of equations Ax = b.static voidmain(String[] args)Unit tests theGaussianEliminationdata type.double[]primal()Returns a solution to the linear system of equations Ax = b.
-
-
-
Constructor Detail
-
GaussianElimination
public GaussianElimination(double[][] A, double[] b)Solves the linear system of equations Ax = b, where A is an m-by-n matrix and b is a length m vector.- Parameters:
A- the m-by-n constraint matrixb- the length m right-hand-side vector- Throws:
IllegalArgumentException- if the dimensions disagree, i.e., the length ofbdoes not equalm
-
-
Method Detail
-
primal
public double[] primal()
Returns a solution to the linear system of equations Ax = b.- Returns:
- a solution x to the linear system of equations
Ax = b;
nullif no such solution
-
isFeasible
public boolean isFeasible()
Returns true if there exists a solution to the linear system of equations Ax = b.- Returns:
trueif there exists a solution to the linear system of equations Ax = b;falseotherwise
-
main
public static void main(String[] args)
Unit tests theGaussianEliminationdata type.- Parameters:
args- the command-line arguments
-
-