Class PrecisionMatrix

java.lang.Object
math.matrix.expressParser.PrecisionMatrix

public class PrecisionMatrix extends Object
Deals with numbers of higher precision than Matrix.
  • Field Details

    • name

      private String name
      The simple name used to label this PrecisionMatrix object.
    • array

      private BigDecimal[][] array
      the data array used to create this PrecisionMatrix object
    • det

      private static BigDecimal det
      attribute used to compute the determinant of the PrecisionMatrix object.
  • Constructor Details

    • PrecisionMatrix

      public PrecisionMatrix(int rows, int cols)
      Parameters:
      rows - The number of rows in the PrecisionMatrix.
      cols - The number of columns in the PrecisionMatrix.
    • PrecisionMatrix

      public PrecisionMatrix(String name)
      Parameters:
      name - the simple name used to identify used by the user to label this PrecisionMatrix object. Assigns name unknown to the PrecisionMatrix object and a 2D array that has just a row and a column
    • PrecisionMatrix

      public PrecisionMatrix(BigDecimal[][] array)
      Parameters:
      array - the data array used to create this PreicionMatrix object
    • PrecisionMatrix

      public PrecisionMatrix(PrecisionMatrix matrix)
      Parameters:
      matrix - constructs a new PrecisionMatrix object having similar properties to the one passed as argument, but holding no reference to its data.
  • Method Details

    • getRows

      public int getRows()
      Returns:
      the number of rows in this matrix object
    • getCols

      public int getCols()
      Returns:
      the number of columns in this matrix object
    • setArray

      public void setArray(BigDecimal[][] array)
      Parameters:
      array - sets the data of this matrix
    • getArray

      public BigDecimal[][] getArray()
      Returns:
      the data of this matrix
    • setDet

      private static void setDet(BigDecimal det)
      Parameters:
      det - the determinant attribute of objects of this class
    • getDet

      private static BigDecimal getDet()
      Returns:
      the determinant
    • setName

      public void setName(String name)
      Parameters:
      name - set's the simple name used to identify used by the user to label this PrecisionMatrix object.
    • getName

      public String getName()
      Returns:
      the simple name used to identify used by the user to label this PrecisionMatrix object.
    • fill

      public void fill()
      Fills this matrix object with values
    • randomFill

      public void randomFill()
      Fills the matrix with randomly generated values between 1 and 101.
    • randomFill

      public void randomFill(int n)
      Fills the matrix with randomly generated values between 1 and n
      Parameters:
      n - the maximum possible size of the integer numbers generated.
    • add

      public PrecisionMatrix add(PrecisionMatrix matrice)
      Parameters:
      matrice - the matrix to be added to this one. The operation is ( this + matrice )
      Returns:
      an array containing the product matrix.
    • subtract

      public PrecisionMatrix subtract(PrecisionMatrix matrice)
      Parameters:
      matrice - the matrix to be subtracted from this one. The operation is ( this - matrice )
      Returns:
      an array containing the product matrix.
    • scalarMultiply

      public PrecisionMatrix scalarMultiply(double scalar)
      Parameters:
      scalar - the constant to be multiplied with this matrix The operation is ( scalar X matrice )
      Returns:
      an array containing the product matrix.
    • scalarDivide

      public PrecisionMatrix scalarDivide(double scalar)
      Parameters:
      scalar - the constant to be multiplied with this matrix The operation is ( matrice/scalar )
      Returns:
      an array containing the scaled matrix.
    • multiply

      public static PrecisionMatrix multiply(PrecisionMatrix matrice1, PrecisionMatrix matrice2)
      The operation of matrix multiplication. For this method to run, The pre-multiplying matrix must have its number of columns equal to the number of rows in the pre-multiplying one. The product matrix is one that has its number of columns equal to the number of columns in the pre-multiplying matrix, and its rows equal to that in the post-multiplying matrix. So if the operation is A X B = C, and A is an m X n matrix while B is an r X p matrix, then r = n is a necessary condition for the operation to occur. Also, C is an m X p matrix.
      Parameters:
      matrice1 - the matrix to be pre-multiplying the other one. The operation is ( matrice1 X matrice2 )
      matrice2 - the post-multiplying matrix
      Returns:
      a new PrecisionMatrix object containing the product matrix of the operation matrice1 X matrice2
    • multiply

      public void multiply(PrecisionMatrix matrice)
      Parameters:
      matrice - the matrix to be multiplied by this one. This operation modifies this matrix and changes its data array into that of the product matrix The operation is ( this X matrice )
    • pow

      public static PrecisionMatrix pow(PrecisionMatrix mat, int pow)
      Parameters:
      mat - the matrix to raise to a given power
      pow - the power to raise this matrix to
      Returns:
      the matrix multiplied by itself..pow times
    • unitMatrix

      public PrecisionMatrix unitMatrix()
      Returns:
      a unit matrix of the same dimension as this matrix object
    • unitMatrix

      public static PrecisionMatrix unitMatrix(int rowSize, int colSize)
      Parameters:
      rowSize - the number of rows that the unit matrix will have
      colSize - the number of columns that the unit matrix will have
      Returns:
      a unit matrix having number of rows = rowSize and number of columns=colSize.
    • unitMatrix

      public static PrecisionMatrix unitMatrix(PrecisionMatrix mat)
      Parameters:
      mat - the PrecisionMatrix object that we wish to construct a unit matrix of similar dimensions for.
      Returns:
      a unit matrix of equal dimensions as this unit matrix.
    • columnJoin

      public static PrecisionMatrix columnJoin(PrecisionMatrix mat1, PrecisionMatrix mat2)
      Place the first PrecisionMatrix object side by side with the second one passed as argument to this method. The result is a new matrix where: if 3 4 5 7 5 9 mat1 = 2 3 1 and mat2 = 4 2 6 1 6 7 5 7 3 in a new matrix object (mat). e.g 3 4 5 7 5 9 2 3 1 4 2 6 1 6 7 5 7 3 A necessary condition for this method to run is that the 2 objects must have an equal number of rows. IF THIS CONDITION IS NOT MET, THE METHOD RETURNS A ZERO MATRIX.
      Parameters:
      mat1 - the first PrecisionMatrix object
      mat2 - the second PrecisionMatrix object that we column join with this one
      Returns:
      a new PrecisionMatrix object that contains this PrecisionMatrix object placed side by side with the PrecisionMatrix object passed as argument.
    • update

      public void update(BigDecimal value, int row, int column)
      Parameters:
      value - The value to insert
      row - The row where the value is to be inserted.
      column - The column where the value is to be inserted.
    • rowJoin

      public static PrecisionMatrix rowJoin(PrecisionMatrix mat1, PrecisionMatrix mat2)
      Place the first PrecisionMatrix object side by side with the second one passed as argument to this method. The result is a new PrecisionMatrix where: if 3 4 5 7 5 9 mat1 = 2 3 1 and mat2 = 4 2 6 1 6 7 5 7 3 in a new PrecisionMatrix object (mat). e.g 3 4 5 2 3 1 1 6 7 7 5 9 4 2 6 5 7 3 A necessary condition for this method to run is that the 2 objects must have an equal number of columns. IF THIS CONDITION IS NOT MET, THE METHOD RETURNS A ZERO PrecisionMatrix.
      Parameters:
      mat1 - the first PrecisionMatrix object
      mat2 - the second PrecisionMatrix object that we row join with this one
      Returns:
      a new PrecisionMatrix object that contains the first PrecisionMatrix object argument placed top to bottom with the second PrecisionMatrix object argument.
    • columnDeleteFromEnd

      public void columnDeleteFromEnd(int column)
      Deletes all the specified number of columns from the PrecisionMatrix object starting from the end of the PrecisionMatrix object
      Parameters:
      column - the number of columns to remove from the PrecisionMatrix object. This method will take the object that calls it and perform this operation on it. So it modifies the PrecisionMatrix object that calls it. Be careful, as data will be lost. e.g if 3 4 5 6 7 8 9 2 1 8 1 4 7 0 A = 3 3 2 1 5 7 1 then the call: A.columnDeleteFromEnd(3) will delete the last three columns in this object leaving: 3 4 5 6 A = 2 1 8 1 3 3 2 1
    • columnDeleteFromStart

      public void columnDeleteFromStart(int column)
      Deletes all the specified number of columns from the PrecisionMatrix object from the beginning of the PrecisionMatrix object
      Parameters:
      column - the number of columns to remove from the PrecisionMatrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the PrecisionMatrix object that calls it. Be careful, as data will be lost. e.g if 3 4 5 6 7 8 9 2 1 8 1 4 7 0 A = 3 3 2 1 5 7 1 then the call: A.columnDeleteFromStart(3) will delete the last three columns in this object leaving: 6 7 8 9 A= 1 4 7 0 1 5 7 1
    • rowDeleteFromEnd

      public void rowDeleteFromEnd(int numOfRows)
      Deletes the specified number of rows from the end of the PrecisionMatrix object
      Parameters:
      numOfRows - the number of rows to remove from the PrecisionMatrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the PrecisionMatrix object that calls it. Be careful, as data will be lost. e.g if 3 4 5 6 2 1 8 1 A = 3 3 2 1 7 8 9 2 4 7 0 5 5 7 1 8 then the call: A.rowDeleteFromEnd(3) will delete the last three rows in this object leaving: 3 4 5 6 2 1 8 1 A = 3 3 2 1
    • rowDeleteFromStart

      public void rowDeleteFromStart(int numOfRows)
      Deletes the specified number of rows from the beginning of the PrecisionMatrix object
      Parameters:
      numOfRows - the number of rows to remove from the PrecisionMatrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the PrecisionMatrix object that calls it. Be careful, as data will be lost. e.g if 3 4 5 6 2 1 8 1 A = 3 3 2 1 7 8 9 2 4 7 0 5 5 7 1 8 then the call: A.rowDeleteFromStart(3) will delete the last three rows in this object leaving: A = 7 8 9 2 4 7 0 5 5 7 1 8
    • reduceToTriangularMatrix

      public PrecisionMatrix reduceToTriangularMatrix()
      Returns:
      an upper triangular matrix obtained by row reduction.
    • solveEquation

      public PrecisionMatrix solveEquation()
      Used to solve a system of simultaneous equations placed in this PrecisionMatrix object.
      Returns:
      a PrecisionMatrix object containing the solution matrix.
    • solveEquation

      public static PrecisionMatrix solveEquation(PrecisionMatrix matrix)
      Used to solve a system of simultaneous equations placed in the PrecisionMatrix object.
      Parameters:
      matrix - The row X row+1 matrix, containing the system of linear equations
      Returns:
      a PrecisionMatrix object containing the solution matrix.
    • transpose

      public PrecisionMatrix transpose()
      Returns:
      the transpose of this PrecisionMatrix object. Does not modify this matrix object but generates the transpose of this PrecisionMatrix object as another PrecisionMatrix object.
    • minor

      public PrecisionMatrix minor(int i, int j)
      Parameters:
      i - the row on which the element whose minor is needed lies.
      j - the column on which the element whose minor is needed lies.
      Returns:
      the minor of this matrix relative to this element.
    • isSquareMatrix

      public boolean isSquareMatrix()
      Returns:
      true if this PrecisionMatrix object is a square matrix.
    • isSystemOfEquations

      public boolean isSystemOfEquations()
      Returns:
      true if this PrecisionMatrix object can represent a system of equations solvable by reduction to triangular form and subsequent evaluation.
    • $2X2determinant

      private static BigDecimal $2X2determinant(PrecisionMatrix m)
      Parameters:
      m - a 2 X 2 matrix
      Returns:
      the determinant of this matrix
    • topRowScalarMultiply

      private static PrecisionMatrix topRowScalarMultiply(PrecisionMatrix m, BigDecimal scalar)
      Parameters:
      m - the matrix whose top row is to be multiplied by a scalar
      scalar - The scalar to employ in multiplying the top row. Multiplies the top row of a matrix by a scalar. This is an important operation during the evaluation of a determinant.
    • mdeterm

      public static void mdeterm()
    • det

      private static BigDecimal det(PrecisionMatrix m)
      Parameters:
      m - the PrecisionMatrix object whose determinant is desired.
      Returns:
      the determinant of the matrix
    • determinant

      public BigDecimal determinant()
      Returns:
      the determinant of this matrix.
    • isMatrixValue

      public static boolean isMatrixValue(String matrixValue)
      Parameters:
      matrixValue - A string that is to be checked if it conforms to valid syntax for representing a matrix in this software.
      Returns:
      true if the command string is a valid matrix.e.g [2,1,4:5,3,-2:4,4,5] value.
    • getRowMatrix

      public PrecisionMatrix getRowMatrix(int row)
      Parameters:
      row - The row in this PrecisionMatrix object to be converted into a new PrecisionMatrix object. This operation generates a new PrecisionMatrix object which is a row matrix.
    • getColumnMatrix

      public PrecisionMatrix getColumnMatrix(int column)
      Parameters:
      column - The column to be converted into a new PrecisionMatrix object. This operation generates a new PrecisionMatrix object which is a column matrix.
    • inverse

      public PrecisionMatrix inverse()
      Returns:
      the inverse of the PrecisionMatrix as another PrecisionMatrix object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of the matrix in rows and columns.
    • main

      public static void main(String[] arg)