Class GaussJordanElimination

java.lang.Object
com.irurueta.algebra.GaussJordanElimination

public class GaussJordanElimination extends Object
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
    Modifier
    Constructor
    Description
    private
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Computes inverse of matrix "a".
    static void
    process(Matrix a, double[] b)
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GaussJordanElimination

      private GaussJordanElimination()
      Constructor. Prevents instantiation.
  • Method Details

    • process

      public static void process(Matrix a, Matrix b) throws SingularMatrixException, WrongSizeException
      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

      public static void process(Matrix a, double[] b) throws SingularMatrixException, WrongSizeException
      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

      public static void inverse(Matrix a) throws SingularMatrixException, WrongSizeException
      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 singular
      WrongSizeException - 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 array
      array2 - 2nd array
      pos1 - 1st position to be swapped
      pos2 - 2nd position to be swapped