Class Matrix
java.lang.Object
math.matrix.expressParser.Matrix
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static double
private static String
$2X2determinantForEigen
(String[][] m) adjoint()
private static String
appendLogic
(double coeff, String variableName, double exp) void
columnDeleteFromEnd
(int column) Deletes all the specified number of columns from the Matrix object starting from the end of the Matrix objectvoid
columnDeleteFromStart
(int column) Deletes all the specified number of columns from the Matrix object from the beginning of the Matrix objectstatic Matrix
columnJoin
(Matrix mat1, Matrix mat2) Place the first Matrix object side by side with the second one passed as argument to this method.private static double
Sarus' rule for computing determinants.double
determ()
Row reduction technique used to compute the determinant of this matrix.double
void
fill()
Fills this matrix object with valuesstatic final String
private static String
findDetEigen
(String[][] cofactors) generateExpressionMap
(String variableName, List<String> scan) Generates the expression map of the expression...double[][]
getArray()
final String
private Matrix
getCofactor
(int rw, int cl) private static String[][]
getCofactorTextArray
(String[][] matrix, int rw, int cl) int
getCols()
getColumnMatrix
(int column) private static double
getDet()
double
getElem
(int row, int col) getName()
private double[]
getRow
(int row) getRowMatrix
(int row) int
getRows()
inverse()
Row reduction technique used to compute the inverse of the matrix.static boolean
isMatrixValue
(String matrixValue) boolean
boolean
static void
(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}minor
(int i, int j) void
static Matrix
The operation of matrix multiplication.Computes the inverse of this Matrix object.static Matrix
static Matrix
void
print()
static void
printTextMatrix
(String[][] mat) void
Fills the matrix with randomly generated values between 1 and 101.void
randomFill
(int n) Fills the matrix with randomly generated values between 1 and nvoid
rowDeleteFromEnd
(int numOfRows) Deletes the specified number of row from the end of the Matrix objectvoid
rowDeleteFromStart
(int numOfRows) Deletes the specified number of row from the beginning of the Matrix objectstatic Matrix
Place the first Matrix object side by side with the second one passed as argument to this method.scalarDivide
(double scalar) scalarMultiply
(double scalar) void
setArray
(double[][] array) private static void
setDet
(double det) void
Used to solve a system of simultaneous equations placed in this Matrix object.static Matrix
solveEquation
(Matrix matrix) Used to solve a system of simultaneous equations placed in the Matrix object.void
swapColumn
(int col1, int col2) void
swapRow
(int row1, int row2) private static Matrix
topRowScalarMultiply
(Matrix m, double scalar) toString()
static Matrix
unitMatrix
(int rowSize, int colSize) static Matrix
unitMatrix
(Matrix mat) private static final String
uniVariableExpressionExpander
(String variableName, String... exprs) private static final String
uniVariableExpressionExpander
(String variableName, String expr1, String expr2) boolean
update
(double value, int row, int column)
-
Field Details
-
lambda
- See Also:
-
name
The simple name used to label this Matrix object. -
array
private double[][] arraythe data array used to create this Matrix object -
det
private static double detattribute used to cofactorDet the detMultiplier of the Matrix object.
-
-
Constructor Details
-
Matrix
public Matrix(int rows, int cols) - Parameters:
rows
- The number of row in the Matrix.cols
- The number of columns in the Matrix.
-
Matrix
- Parameters:
name
- the simple name used to identify used by the user to label this Matrix object. Assigns name unknown to the Matrix object and a 2D array that has just a row and a column
-
Matrix
public Matrix(double[][] array) - Parameters:
array
- the data array used to create this Matrix object
-
Matrix
- Parameters:
matrix
- constructs a new Matrix 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 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) -
setDet
private static void setDet(double det) - Parameters:
det
- the detMultiplier attribute of objects of this class
-
getDet
private static double getDet()- Returns:
- the detMultiplier
-
setName
- Parameters:
name
- set's the simple name used to identify used by the user to label this Matrix object.
-
getName
- Returns:
- the simple name used to identify used by the user to label this Matrix object.
-
getRow
private double[] getRow(int row) - Parameters:
row
- The row whose contents we desire.- Returns:
- the contents of the row.
-
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
-
subtract
-
scalarMultiply
- Parameters:
scalar
- the constant to be multiplied with this matrix The operation is ( scalar X matrice )- Returns:
- an array containing the product matrix.
-
scalarDivide
- Parameters:
scalar
- the constant to be multiplied with this matrix The operation is ( matrice/scalar )- Returns:
- an array containing the scaled matrix.
-
multiply
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 Matrix object containing the product matrix of the operation matrice1 X matrice2
-
multiply
- 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
-
power
-
unitMatrix
- Returns:
- a unit matrix of the same dimension as this matrix object
-
unitMatrix
- Parameters:
rowSize
- the number of row that the unit matrix will havecolSize
- the number of columns that the unit matrix will have- Returns:
- a unit matrix having number of row = rowSize and number of columns=colSize.
-
unitMatrix
-
columnJoin
Place the first Matrix 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 Matrix objectmat2
- the second Matrix object that we column join with this one- Returns:
- a new Matrix object that contains this Matrix object placed side by side with the Matrix object passed as argument.
-
update
public boolean update(double value, int row, int column) - Parameters:
value
- The value to insertrow
- The row where the value is to be inserted.column
- The column where the value is to be inserted.
-
rowJoin
Place the first Matrix 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 Matrix objectmat2
- the second Matrix object that we row join with this one- Returns:
- a new Matrix object that contains the first Matrix object argument placed top to bottom with the second Matrix object argument.
-
columnDeleteFromEnd
public void columnDeleteFromEnd(int column) Deletes all the specified number of columns from the Matrix object starting from the end of the Matrix object- Parameters:
column
- the number of columns to remove from the Matrix object. This method will take the object that calls it and perform this operation on it. So it modifies the Matrix 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 Matrix object from the beginning of the Matrix object- Parameters:
column
- the number of columns to remove from the Matrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the Matrix 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 Matrix object- Parameters:
numOfRows
- the number of row to remove from the Matrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the Matrix 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 Matrix object- Parameters:
numOfRows
- the number of row to remove from the Matrix object's beginning. This method will take the object that calls it and perform this operation on it. So it modifies the Matrix 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
-
reduceToTriangularMatrix
- Returns:
- an upper triangular matrix obtained by row reduction.
-
reduceToRowEchelonMatrix
- Returns:
- an upper triangular matrix obtained by row reduction.
-
solveEquation
Used to solve a system of simultaneous equations placed in this Matrix object.- Returns:
- a Matrix object containing the solution matrix.
-
solveEquation
-
transpose
- Returns:
- the transpose of this Matrix object. Does not modify this matrix object but generates the transpose of this Matrix object as another Matrix object.
-
adjoint
-
getCofactorMatrix
- Returns:
- a matrix that contains the cofactors of the elements of this Matrix.
-
minor
- 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 Matrix object is a square matrix.
-
isSystemOfEquations
public boolean isSystemOfEquations()- Returns:
- true if this Matrix object can represent a system of equations solvable by reduction to triangular form and subsequent evaluation.
-
$2X2determinant
- Parameters:
m
- a 2 X 2 matrix- Returns:
- the detMultiplier of this matrix
-
$2X2determinantForEigen
-
topRowScalarMultiply
-
det
Sarus' rule for computing determinants. This technique is too slow and memory intensive for large matrices..n>=10. Please use the determ() instance method. It uses a O(cube_n) algorithm as against this method's O(n!)- Parameters:
m
- the Matrix object whose detMultiplier is desired.- Returns:
- the detMultiplier of the matrix
-
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.
-
isMatrixValue
- 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
-
printTextMatrix
- Parameters:
mat
- The string matrix
-
getRowMatrix
- Parameters:
row
- The row in this Matrix object to be converted into a new Matrix object. This operation generates a new Matrix object which is a row matrix.
-
getColumnMatrix
- Parameters:
column
- The column to be converted into a new Matrix object. This operation generates a new Matrix object which is a column matrix.
-
oldInverse
Computes the inverse of this Matrix 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 Matrix as another Matrix object.
-
inverse
Row reduction technique used to compute the inverse of the matrix. Always use this technique.- Returns:
- the inverse of the Matrix as another Matrix 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 Matrix as another Matrix object.
-
findDetEigen
-
getCharacteristicPolynomialForEigenVector
-
findCharacteristicPolynomialForEigenValues
-
getCofactor
- Parameters:
rw
- The row of a given elementcl
- The position of that element- Returns:
- the cofactor sub-matrix used to calculate the cofactor element of the specified position
-
getCofactorTextArray
-
generateExpressionMap
Generates the expression map of the expression... a map whose keys are the powers of the variable of the expression and whose values are the coefficients of the variables. e.g. 3x^2-2x+1 would produce: [{2,3},{1,-2},{0,1}]- Parameters:
variableName
- The name of the variablescan
- The list to smoothen- Returns:
- the expression map
-
uniVariableExpressionExpander
-
uniVariableExpressionExpander
-
appendLogic
-
print
public void print() -
main
(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
-