Class MatrixOld

java.lang.Object
com.github.gbenroscience.math.matrix.expressParser.MatrixOld

public class MatrixOld extends Object
Author:
GBEMIRO
  • Field Details

  • Constructor Details

    • MatrixOld

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

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

      public MatrixOld(double[][] array)
      Parameters:
      array - the data array used to create this MatrixOld object
    • MatrixOld

      public MatrixOld(MatrixOld matrix)
      Parameters:
      matrix - constructs a new MatrixOld 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 row in this matrix object
    • getCols

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

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

      public double[][] getArray()
      Returns:
      the data of this matrix
    • getElem

      public double getElem(int row, int col)
    • setName

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

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

      public void swapRow(int row1, int row2)
      Parameters:
      row1 - The first row.
      row2 - The second row. BE CAREFUL!!!!
      THIS METHOD ACTS ON THE MATRIX OBJECT ON WHICH IT IS CALLED AND MODIFIES IT!
    • swapColumn

      public void swapColumn(int col1, int col2)
      Parameters:
      col1 - The first row.
      col2 - The second row. BE CAREFUL!!!!
      THIS METHOD ACTS ON THE MATRIX OBJECT ON WHICH IT IS CALLED AND MODIFIES IT!
    • fill

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

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

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

      public MatrixOld 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 MatrixOld 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 MatrixOld multiply(MatrixOld matrice1, MatrixOld 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 row 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 row 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 MatrixOld object containing the product matrix of the operation matrice1 X matrice2
    • multiply

      public void multiply(MatrixOld 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 MatrixOld pow(MatrixOld mat, int pow)
      Parameters:
      mat - the matrix to raise to a given power
      pow - the power to raise this matrix to
      Returns:
      the
    • power

      public static MatrixOld power(MatrixOld mat, int pow)
    • unitMatrixOld

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

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

      public static MatrixOld unitMatrixOld(MatrixOld mat)
      Parameters:
      mat - the MatrixOld 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 MatrixOld columnJoin(MatrixOld mat1, MatrixOld mat2)
      Place the first MatrixOld 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 row. IF THIS CONDITION IS NOT MET, THE METHOD RETURNS A ZERO MATRIX.
      Parameters:
      mat1 - the first MatrixOld object
      mat2 - the second MatrixOld object that we column join with this one
      Returns:
      a new MatrixOld object that contains this MatrixOld object placed side by side with the MatrixOld object passed as argument.
    • update

      public boolean update(double 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 MatrixOld rowJoin(MatrixOld mat1, MatrixOld mat2)
      Place the first MatrixOld 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 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 MATRIX.
      Parameters:
      mat1 - the first MatrixOld object
      mat2 - the second MatrixOld object that we row join with this one
      Returns:
      a new MatrixOld object that contains the first MatrixOld object argument placed top to bottom with the second MatrixOld object argument.
    • columnDeleteFromEnd

      public void columnDeleteFromEnd(int column)
      Deletes all the specified number of columns from the MatrixOld object starting from the end of the MatrixOld object
      Parameters:
      column - the number of columns to remove from the MatrixOld object. This method will take the object that calls it and perform this operation on it. So it modifies the MatrixOld 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 MatrixOld object from the beginning of the MatrixOld object
      Parameters:
      column - the number of columns to remove from the MatrixOld object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the MatrixOld 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 row from the end of the MatrixOld object
      Parameters:
      numOfRows - the number of row to remove from the MatrixOld object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the MatrixOld 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 row 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 row from the beginning of the MatrixOld object
      Parameters:
      numOfRows - the number of row to remove from the MatrixOld object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the MatrixOld 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 row in this object leaving: A = 7 8 9 2 4 7 0 5 5 7 1 8
    • reduceToTriangularMatrixOld

      public MatrixOld reduceToTriangularMatrixOld()
      Returns:
      an upper triangular matrix obtained by row reduction.
    • reduceToRowEchelonMatrixOld

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

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

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

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

      public MatrixOld adjoint()
    • getCofactorMatrixOld

      public MatrixOld getCofactorMatrixOld()
      Returns:
      a matrix that contains the cofactors of the elements of this MatrixOld.
    • minor

      public MatrixOld 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.
    • isSquareMatrixOld

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

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

      public double determinant()
      Returns:
      the determinant of this matrix using a row reduction technique.
    • 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.
    • isMatrixOldValue

      public static boolean isMatrixOldValue(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.
    • toString

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

      public static void printTextMatrixOld(String[][] mat)
      Parameters:
      mat - The string matrix
    • getRowMatrixOld

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

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

      public MatrixOld oldInverse()
      Computes the inverse of this MatrixOld object. This technique should never be used in practise as it is a mere proof of concept. It computes the inverse by computing the roots of the equations and then reverse engineering the form A.x = B to get the inverse matrix.
      Returns:
      the inverse of the MatrixOld as another MatrixOld object.
    • inverse

      public MatrixOld inverse()
      Row reduction technique used to compute the inverse of the matrix. Always use this technique.
      Returns:
      the inverse of the MatrixOld as another MatrixOld object.
    • determ

      public double determ()
      Row reduction technique used to compute the determinant of this matrix. The other method using recursion is not worth it above n = 10; The memory consumed by the process and the time used to compute it is incomparable to this method's performance.
      Returns:
      the inverse of the MatrixOld as another MatrixOld object.
    • getCharacteristicPolynomialForEigenVector

      public final String getCharacteristicPolynomialForEigenVector()
    • findCharacteristicPolynomialForEigenValues

      public static final String findCharacteristicPolynomialForEigenValues(MatrixOld m)
      Parameters:
      m - The MatrixOld object
      Returns:
      the characteristic polynomial
    • print

      public void print()
    • main

      public static void main(String... args)
      (2-x)(3-x)(1-x)=(6-5x+x^2)(1-x)=6-11x+6x^2-x^3 {1, 2, 3, 4, 5} {6, 7, 8, 9, 0} {1, 2, 3, 4, 5} {6, 7, 8, 9, 0} {1, 2, 3, 4, 5}
      Parameters:
      args - The command line args