Package org.moeaframework.util
Class LinearAlgebra
java.lang.Object
org.moeaframework.util.LinearAlgebra
Collection of linear algebra routines.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]
lsolve
(double[][] A, double[] b) Solves a system of linear equations in the formA*x = b
using Guassian Elimination with Partial Pivioting.
-
Method Details
-
lsolve
public static double[] lsolve(double[][] A, double[] b) Solves a system of linear equations in the formA*x = b
using Guassian Elimination with Partial Pivioting.A
must be a square matrix of sizeN * N
, andb
a vector of lengthN
.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
onN < 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
- theA
matrixb
- theb
vector- Returns:
- the solved values for
x
- Throws:
org.apache.commons.math3.linear.SingularMatrixException
- if the matrix is singular or nearly singularorg.apache.commons.math3.exception.DimensionMismatchException
- if the dimensions of the provided matrix and vector are not valid- See Also:
-