Package com.irurueta.algebra
Class GaussJordanElimination
java.lang.Object
com.irurueta.algebra.GaussJordanElimination
Computes Gauss-Jordan elimination for provided matrix using full pivoting,
which provides greater stability.
Gauss-Jordan elimination can be used to compute matrix inversion or to
solve linear systems of equations of the form A * x = b, where Gauss-Jordan
elimination both inverts matrix A and finds solution x at the same time.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Computes inverse of matrix "a".static void
Computes Gauss-Jordan elimination by attempting to solve linear system of equations a * x = b.static void
Computes Gauss-Jordan elimination by attempting to solve linear system of equations a * x = b.private static void
swap
(double[] array1, double[] array2, int pos1, int pos2) Swaps values in arrays at provided positions
-
Constructor Details
-
GaussJordanElimination
private GaussJordanElimination()Constructor. Prevents instantiation.
-
-
Method Details
-
process
Computes Gauss-Jordan elimination by attempting to solve linear system of equations a * x = b. This method computes inverse of matrix "a", and modifies provided matrix so that its inverse is stored in it after execution of this method. Likewise, this method modifies b so that solution x is stored on it after execution of this method. This method can only be used on squared a matrices.- Parameters:
a
- linear system of equations matrix. Will contain its inverse after execution of this method.b
- linear system of equations parameters. Will contain the solution after execution of this method. If null is provided, solution is not stored but matrix inverse is computed anyway. Each column of b is considered a new linear system of equations and its solution x is computed on the corresponding column of b.- Throws:
SingularMatrixException
- if provided matrix "a" is found to be singular.WrongSizeException
- if provided matrix "a" is not square.
-
process
Computes Gauss-Jordan elimination by attempting to solve linear system of equations a * x = b. This method computes inverse of matrix "a", and modifies provided matrix so that its inverse is stored in it after execution of this method. Likewise, this method modifies b so that solution x is stored on it after execution of this method. This method can only be used on squared a matrices.- Parameters:
a
- linear system of equations matrix. Will contain its inverse after execution of this method.b
- linear system of equations parameters. Will contain the solution after execution of this method. If null is provided, solution is not stored but matrix inverse is computed anyway.- Throws:
SingularMatrixException
- if provided matrix "a" is found to be singular.WrongSizeException
- if provided matrix "a" is not square.
-
inverse
Computes inverse of matrix "a". No solution of a linear system of equations is computed. This method modifies provided matrix storing the inverse on it after execution of this method- Parameters:
a
- matrix to be inverted.- Throws:
SingularMatrixException
- if provided matrix is found to be singularWrongSizeException
- if provided matrix is not square
-
swap
private static void swap(double[] array1, double[] array2, int pos1, int pos2) Swaps values in arrays at provided positions- Parameters:
array1
- 1st arrayarray2
- 2nd arraypos1
- 1st position to be swappedpos2
- 2nd position to be swapped
-