Class LinearAlgebra

java.lang.Object
org.moeaframework.util.LinearAlgebra

public class LinearAlgebra extends Object
Collection of linear algebra routines.
  • Method Details

    • lsolve

      public static double[] lsolve(double[][] A, double[] b)
      Solves a system of linear equations in the form A*x = b using Guassian Elimination with Partial Pivioting. A must be a square matrix of size N * N, and b a vector of length N.

      This method modifies the arguments! Pass in copies if you need to retain the original values.

      In our testing, this method is about 5-10x faster than other solvers like Commons Math's LUDecomposition on N < 50, however these other approaches may have better numerical stability. If needed, this can be replaced with:

         RealMatrix A = new Array2DRowRealMatrix(...);
         RealVector b = new ArrayRealVector(...);
         RealVector x = new LUDecomposition(A).getSolver().solve(b);
       
      Parameters:
      A - the A matrix
      b - the b vector
      Returns:
      the solved values for x
      Throws:
      org.apache.commons.math3.linear.SingularMatrixException - if the matrix is singular or nearly singular
      org.apache.commons.math3.exception.DimensionMismatchException - if the dimensions of the provided matrix and vector are not valid
      See Also: