Class LinearSystem
- java.lang.Object
-
- org.hortonmachine.gears.utils.math.matrixes.Matrix
-
- org.hortonmachine.gears.utils.math.matrixes.SquareMatrix
-
- org.hortonmachine.gears.utils.math.matrixes.LinearSystem
-
- Direct Known Subclasses:
InvertibleMatrix
public class LinearSystem extends SquareMatrix
From: Java Number Cruncher The Java Programmer's Guide to Numerical Computation by Ronald Mak Solve a system of linear equations using LU decomposition.
-
-
Field Summary
Fields Modifier and Type Field Description protected intexchangeCountrow exchange countprotected SquareMatrixLUdecomposed matrix A = LUprotected int[]permutationrow index permutation vector
-
Constructor Summary
Constructors Constructor Description LinearSystem(double[][] values)Constructor.LinearSystem(int n)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecompose()Compute the upper triangular matrix U and lower triangular matrix L such that A = L*U.protected voidreset()Reset.protected voidset(double[][] values)Set the values of the matrix.voidset(int r, int c, double value)Set the value of element [r,c] in the matrix.voidsetColumn(ColumnVector cv, int c)Set a column of this matrix from a column vector.voidsetRow(RowVector rv, int r)Set a row of this matrix from a row vector.ColumnVectorsolve(ColumnVector b, boolean improve)Solve Ax = b for x using the Gaussian elimination algorithm.-
Methods inherited from class org.hortonmachine.gears.utils.math.matrixes.SquareMatrix
add, multiply, subtract
-
-
-
-
Field Detail
-
LU
protected SquareMatrix LU
decomposed matrix A = LU
-
permutation
protected int[] permutation
row index permutation vector
-
exchangeCount
protected int exchangeCount
row exchange count
-
-
Method Detail
-
set
protected void set(double[][] values)
Set the values of the matrix.- Overrides:
setin classSquareMatrix- Parameters:
values- the 2-d array of values
-
set
public void set(int r, int c, double value) throws MatrixExceptionSet the value of element [r,c] in the matrix.- Overrides:
setin classMatrix- Parameters:
r- the row index, 0..nRowsc- the column index, 0..nRowsvalue- the value- Throws:
matrix.MatrixException- for invalid indexMatrixException
-
setRow
public void setRow(RowVector rv, int r) throws MatrixException
Set a row of this matrix from a row vector.- Overrides:
setRowin classMatrix- Parameters:
rv- the row vectorr- the row index- Throws:
matrix.MatrixException- for an invalid index or an invalid vector sizeMatrixException
-
setColumn
public void setColumn(ColumnVector cv, int c) throws MatrixException
Set a column of this matrix from a column vector.- Overrides:
setColumnin classMatrix- Parameters:
cv- the column vectorc- the column index- Throws:
matrix.MatrixException- for an invalid index or an invalid vector sizeMatrixException
-
reset
protected void reset()
Reset. Invalidate LU and the permutation vector.
-
solve
public ColumnVector solve(ColumnVector b, boolean improve) throws MatrixException
Solve Ax = b for x using the Gaussian elimination algorithm.- Parameters:
b- the right-hand-side column vectorimprove- true to improve the solution- Returns:
- the solution column vector
- Throws:
matrix.MatrixException- if an error occurredMatrixException
-
decompose
protected void decompose() throws MatrixExceptionCompute the upper triangular matrix U and lower triangular matrix L such that A = L*U. Store L and U together in matrix LU. Compute the permutation vector permutation of the row indices.- Throws:
matrix.MatrixException- for a zero row or a singular matrixMatrixException
-
-