Class GenMatrix<C extends RingElem<C>>

java.lang.Object
edu.jas.vector.GenMatrix<C>
All Implemented Interfaces:
AbelianGroupElem<GenMatrix<C>>, AlgebraElem<GenMatrix<C>,C>, Element<GenMatrix<C>>, MonoidElem<GenMatrix<C>>, RingElem<GenMatrix<C>>, Serializable, Comparable<GenMatrix<C>>

public class GenMatrix<C extends RingElem<C>> extends Object implements AlgebraElem<GenMatrix<C>,C>
GenMatrix implements a generic matrix algebra over RingElem entries. Matrix has n columns and m rows over C.
See Also:
  • Field Details

  • Constructor Details

    • GenMatrix

      public GenMatrix(GenMatrixRing<C> r)
      Constructor for zero GenMatrix.
      Parameters:
      r - matrix ring
    • GenMatrix

      public GenMatrix(GenMatrixRing<C> r, List<List<C>> m)
      Constructor for GenMatrix.
      Parameters:
      r - matrix ring
      m - matrix
    • GenMatrix

      public GenMatrix(GenMatrixRing<C> r, ArrayList<ArrayList<C>> m)
      Constructor for GenMatrix.
      Parameters:
      r - matrix ring
      m - matrix
    • GenMatrix

      public GenMatrix(GenMatrixRing<C> r, C[][] m)
      Constructor for GenMatrix.
      Parameters:
      r - matrix ring
      m - matrix
  • Method Details

    • get

      public C get(int i, int j)
      Get element at row i, column j.
      Parameters:
      i - row index.
      j - column index.
      Returns:
      this(i,j).
    • setMutate

      public void setMutate(int i, int j, C el)
      Set element at row i, column j. Mutates this matrix.
      Parameters:
      i - row index.
      j - column index.
      el - element to set.
    • set

      public GenMatrix<C> set(int i, int j, C el)
      Set element at row i, column j.
      Parameters:
      i - row index.
      j - column index.
      el - element to set.
      Returns:
      new matrix m, with m(i,j) == el.
    • getColumn

      public GenVector<C> getColumn(int i)
      Get column i.
      Parameters:
      i - column index.
      Returns:
      this(*,i) as vector.
    • getRow

      public GenVector<C> getRow(int i)
      Get row i.
      Parameters:
      i - row index.
      Returns:
      this(i,*) as vector.
    • getDiagonal

      public GenVector<C> getDiagonal()
      Get diagonal.
      Returns:
      diagonal(this) as vector.
    • trace

      public C trace()
      Trace.
      Returns:
      sum of diagonal elements.
    • getUpper

      public GenMatrix<C> getUpper()
      Get upper triangular U matrix.
      Returns:
      U as matrix with equal length rows.
    • getUpperScaled

      public GenMatrix<C> getUpperScaled()
      Get upper triangular U matrix with diagonal 1.
      Returns:
      U as matrix with equal length rows and diagonal 1.
    • getLower

      public GenMatrix<C> getLower()
      Get lower triangular L matrix.
      Returns:
      L as matrix with equal length rows.
    • toString

      public String toString()
      Get the String representation as RingElem.
      Overrides:
      toString in class Object
      See Also:
    • toScript

      public String toScript()
      Get a scripting compatible string representation.
      Specified by:
      toScript in interface Element<C extends RingElem<C>>
      Returns:
      script compatible representation for this Element.
      See Also:
    • toScriptFactory

      public String toScriptFactory()
      Get a scripting compatible string representation of the factory.
      Specified by:
      toScriptFactory in interface Element<C extends RingElem<C>>
      Returns:
      script compatible representation for this ElemFactory.
      See Also:
    • factory

      public GenMatrixRing<C> factory()
      Get the corresponding element factory.
      Specified by:
      factory in interface Element<C extends RingElem<C>>
      Returns:
      factory for this Element.
      See Also:
    • copy

      public GenMatrix<C> copy()
      Copy method.
      Specified by:
      copy in interface Element<C extends RingElem<C>>
      Returns:
      Creates and returns a copy of this Element.
      See Also:
    • stack

      public GenMatrix<C> stack(GenMatrixRing<C> st, GenMatrix<C> b)
      Stack method.
      Parameters:
      st - stacked matrix ring.
      b - other matrix.
      Returns:
      stacked matrix, this on top of other.
    • concat

      public GenMatrix<C> concat(GenMatrixRing<C> cc, GenMatrix<C> b)
      Concat method.
      Parameters:
      cc - concated matrix ring.
      b - other matrix.
      Returns:
      concated matrix, this before of other.
    • isZERO

      public boolean isZERO()
      Test if this is equal to a zero matrix.
      Specified by:
      isZERO in interface AbelianGroupElem<C extends RingElem<C>>
      Returns:
      true if this is 0, else false.
    • isONE

      public boolean isONE()
      Test if this is one.
      Specified by:
      isONE in interface MonoidElem<C extends RingElem<C>>
      Returns:
      true if this is 1, else false.
    • isDiagonal

      public boolean isDiagonal()
      Test if this is a non-zero diagonal matrix.
      Returns:
      true if this is non-zero diagonal, else false.
    • equals

      public boolean equals(Object other)
      Comparison with any other object.
      Specified by:
      equals in interface Element<C extends RingElem<C>>
      Overrides:
      equals in class Object
      Parameters:
      other -
      Returns:
      true if this is equal to b, else false.
      See Also:
    • hashCode

      public int hashCode()
      Hash code for this GenMatrix.
      Specified by:
      hashCode in interface Element<C extends RingElem<C>>
      Overrides:
      hashCode in class Object
      Returns:
      the hashCode.
      See Also:
    • compareTo

      public int compareTo(GenMatrix<C> b)
      compareTo, lexicogaphical comparison.
      Specified by:
      compareTo in interface Comparable<C extends RingElem<C>>
      Specified by:
      compareTo in interface Element<C extends RingElem<C>>
      Parameters:
      b - other
      Returns:
      1 if (this < b), 0 if (this == b) or -1 if (this > b).
    • isUnit

      public boolean isUnit()
      Test if this is a unit. I.e. there exists x with this.multiply(x).isONE() == true. Tests if matrix is not singular. Was previously a test if all diagonal elements are units and all other elements are zero.
      Specified by:
      isUnit in interface MonoidElem<C extends RingElem<C>>
      Returns:
      true if this is a unit, else false.
    • signum

      public int signum()
      sign of matrix.
      Specified by:
      signum in interface AbelianGroupElem<C extends RingElem<C>>
      Returns:
      1 if (this < 0), 0 if (this == 0) or -1 if (this > 0).
    • sum

      public GenMatrix<C> sum(GenMatrix<C> b)
      Sum of matrices.
      Specified by:
      sum in interface AbelianGroupElem<C extends RingElem<C>>
      Parameters:
      b - other matrix.
      Returns:
      this+b
    • subtract

      public GenMatrix<C> subtract(GenMatrix<C> b)
      Difference of matrices.
      Specified by:
      subtract in interface AbelianGroupElem<C extends RingElem<C>>
      Parameters:
      b - other matrix.
      Returns:
      this-b
    • negate

      public GenMatrix<C> negate()
      Negative of this matrix.
      Specified by:
      negate in interface AbelianGroupElem<C extends RingElem<C>>
      Returns:
      -this
    • abs

      public GenMatrix<C> abs()
      Absolute value of this matrix.
      Specified by:
      abs in interface AbelianGroupElem<C extends RingElem<C>>
      Returns:
      abs(this)
    • multiply

      public GenMatrix<C> multiply(C s)
      Product of this matrix with scalar.
      Parameters:
      s - scalar.
      Returns:
      this*s
    • scalarMultiply

      public GenMatrix<C> scalarMultiply(C s)
      Product of this matrix with scalar.
      Specified by:
      scalarMultiply in interface AlgebraElem<GenMatrix<C extends RingElem<C>>,C extends RingElem<C>>
      Parameters:
      s - scalar
      Returns:
      this*s
    • leftScalarMultiply

      public GenMatrix<C> leftScalarMultiply(C s)
      Left product of this matrix with scalar.
      Parameters:
      s - scalar
      Returns:
      s*this
    • linearCombination

      public GenMatrix<C> linearCombination(C s, GenMatrix<C> b, C t)
      Linear compination of this matrix with scalar multiple of other matrix.
      Specified by:
      linearCombination in interface AlgebraElem<GenMatrix<C extends RingElem<C>>,C extends RingElem<C>>
      Parameters:
      s - scalar
      b - other matrix.
      t - scalar
      Returns:
      this*s+b*t
    • linearCombination

      public GenMatrix<C> linearCombination(GenMatrix<C> b, C t)
      Linear combination of this matrix with scalar multiple of other matrix.
      Specified by:
      linearCombination in interface AlgebraElem<GenMatrix<C extends RingElem<C>>,C extends RingElem<C>>
      Parameters:
      b - other matrix.
      t - scalar
      Returns:
      this+b*t
    • linearCombination

      public GenMatrix<C> linearCombination(C t, GenMatrix<C> b)
      Left linear combination of this matrix with scalar multiple of other matrix.
      Parameters:
      t - scalar
      b - other matrix.
      Returns:
      this+t*b
    • leftLinearCombination

      public GenMatrix<C> leftLinearCombination(C s, C t, GenMatrix<C> b)
      left linear compination of this matrix with scalar multiple of other matrix.
      Parameters:
      s - scalar
      t - scalar
      b - other matrix.
      Returns:
      s*this+t*b
    • transpose

      public GenMatrix<C> transpose(GenMatrixRing<C> tr)
      Transposed matrix.
      Parameters:
      tr - transposed matrix ring.
      Returns:
      transpose(this)
    • transpose

      public GenMatrix<C> transpose()
      Transposed matrix.
      Returns:
      transpose(this)
    • multiply

      public GenMatrix<C> multiply(GenMatrix<C> S)
      Multiply this with S.
      Specified by:
      multiply in interface MonoidElem<C extends RingElem<C>>
      Parameters:
      S - other matrix.
      Returns:
      this * S.
    • multiplySimple

      public GenMatrix<C> multiplySimple(GenMatrix<C> S)
      Multiply this with S. Simple unblocked algorithm.
      Parameters:
      S - other matrix.
      Returns:
      this * S.
    • divide

      public GenMatrix<C> divide(GenMatrix<C> S)
      Divide this by S.
      Specified by:
      divide in interface MonoidElem<C extends RingElem<C>>
      Parameters:
      S - other matrix.
      Returns:
      this * S^{-1}.
    • divideLeft

      public GenMatrix<C> divideLeft(GenMatrix<C> S)
      Divide left this by S.
      Parameters:
      S - other matrix.
      Returns:
      S^{-1} * this.
    • remainder

      public GenMatrix<C> remainder(GenMatrix<C> S)
      Remainder after division of this by S.
      Specified by:
      remainder in interface MonoidElem<C extends RingElem<C>>
      Parameters:
      S - other matrix.
      Returns:
      this - (this / S) * S.
    • quotientRemainder

      public GenMatrix<C>[] quotientRemainder(GenMatrix<C> S)
      Quotient and remainder by division of this by S.
      Specified by:
      quotientRemainder in interface MonoidElem<C extends RingElem<C>>
      Parameters:
      S - a GenMatrix
      Returns:
      [this/S, this - (this/S)*S].
    • inverse

      public GenMatrix<C> inverse()
      Inverse of this.
      Specified by:
      inverse in interface MonoidElem<C extends RingElem<C>>
      Returns:
      x with this * x = 1, if it exists.
      See Also:
    • gcd

      public GenMatrix<C> gcd(GenMatrix<C> b)
      Greatest common divisor.
      Specified by:
      gcd in interface RingElem<C extends RingElem<C>>
      Parameters:
      b - other element.
      Returns:
      gcd(this,b).
    • egcd

      public GenMatrix<C>[] egcd(GenMatrix<C> b)
      Extended greatest common divisor.
      Specified by:
      egcd in interface RingElem<C extends RingElem<C>>
      Parameters:
      b - other element.
      Returns:
      [ gcd(this,b), c1, c2 ] with c1*this + c2*b = gcd(this,b).