Class LinAlg<C extends RingElem<C>>

java.lang.Object
edu.jas.vector.LinAlg<C>
Type Parameters:
C - coefficient type
All Implemented Interfaces:
Serializable

public class LinAlg<C extends RingElem<C>> extends Object implements Serializable
Linear algebra methods. Implements linear algebra computations and tests, mainly based on Gauss elimination. Partly based on LU_decomposition. Computation of Null space basis, row echelon form, inverses and ranks.
See Also:
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
  • Constructor Details

    • LinAlg

      public LinAlg()
      Constructor.
  • Method Details

    • decompositionLU

      public List<Integer> decompositionLU(GenMatrix<C> A)
      Matrix LU decomposition. Matrix A is replaced by its LU decomposition. A contains a copy of both matrices L-E and U as A=(L-E)+U such that P*A=L*U. The permutation matrix is not stored as a matrix, but in an integer vector P of size N+1 containing column indexes where the permutation matrix has "1". The last element P[N]=S+N, where S is the number of row exchanges needed for determinant computation, det(P)=(-1)^S
      Parameters:
      A - a n×n matrix.
      Returns:
      permutation vector P and modified matrix A.
    • solveLU

      public GenVector<C> solveLU(GenMatrix<C> A, List<Integer> P, GenVector<C> b)
      Solve with LU decomposition.
      Parameters:
      A - a n×n matrix in LU decomposition.
      P - permutation vector.
      b - right hand side vector.
      Returns:
      x solution vector of A*x = b.
    • solve

      public GenVector<C> solve(GenMatrix<C> A, GenVector<C> b)
      Solve linear system of equations.
      Parameters:
      A - a n×n matrix.
      b - right hand side vector.
      Returns:
      x solution vector of A*x = b.
    • determinantLU

      public C determinantLU(GenMatrix<C> A, List<Integer> P)
      Determinant with LU decomposition.
      Parameters:
      A - a n×n matrix in LU decomposition.
      P - permutation vector.
      Returns:
      d determinant of A.
    • inverseLU

      public GenMatrix<C> inverseLU(GenMatrix<C> A, List<Integer> P)
      Inverse with LU decomposition.
      Parameters:
      A - a n×n matrix in LU decomposition.
      P - permutation vector.
      Returns:
      inv(A) with A * inv(A) == 1.
    • nullSpaceBasis

      public List<GenVector<C>> nullSpaceBasis(GenMatrix<C> A)
      Matrix Null Space basis, cokernel. From the transpose matrix At it computes the kernel with At*v_i = 0.
      Parameters:
      A - a n×n matrix.
      Returns:
      V a list of basis vectors (v_1, ..., v_k) with v_i*A == 0.
    • rankNS

      public long rankNS(GenMatrix<C> A)
      Rank via null space.
      Parameters:
      A - a n×n matrix.
      Returns:
      r rank of A.
    • rowEchelonForm

      public GenMatrix<C> rowEchelonForm(GenMatrix<C> A)
      Matrix row echelon form construction. Matrix A is replaced by its row echelon form, an upper triangle matrix.
      Parameters:
      A - a n×m matrix.
      Returns:
      A row echelon form of A, matrix A is modified.
    • rankRE

      public long rankRE(GenMatrix<C> A)
      Rank via row echelon form.
      Parameters:
      A - a n×n matrix.
      Returns:
      r rank of A.
    • rowEchelonFormSparse

      public GenMatrix<C> rowEchelonFormSparse(GenMatrix<C> A)
      Matrix row echelon form construction. Matrix A is replaced by its row echelon form, an upper triangle matrix with less non-zero entries. No column swaps and transforms are performed as with the Gauss-Jordan algorithm.
      Parameters:
      A - a n×m matrix.
      Returns:
      A sparse row echelon form of A, matrix A is modified.
    • fractionfreeGaussElimination

      public List<Integer> fractionfreeGaussElimination(GenMatrix<C> A)
      Matrix fraction free Gauss elimination. Matrix A is replaced by its fraction free LU decomposition. A contains a copy of both matrices L-E and U as A=(L-E)+U such that P*A=L*U. TODO: L is not computed but 0. The permutation matrix is not stored as a matrix, but in an integer vector P of size N+1 containing column indexes where the permutation matrix has "1". The last element P[N]=S+N, where S is the number of row exchanges needed for determinant computation, det(P)=(-1)^S
      Parameters:
      A - a n×n matrix.
      Returns:
      permutation vector P and modified matrix A.