Package math.matrix.expressParser
Class PrecisionMatrix
java.lang.Object
math.matrix.expressParser.PrecisionMatrix
public class PrecisionMatrix
extends java.lang.Object
Deals with numbers of higher
precision than Matrix.
-
Constructor Summary
Constructors Constructor Description PrecisionMatrix(int rows, int cols)PrecisionMatrix(java.lang.String name)PrecisionMatrix(java.math.BigDecimal[][] array)PrecisionMatrix(PrecisionMatrix matrix) -
Method Summary
Modifier and Type Method Description PrecisionMatrixadd(PrecisionMatrix matrice)voidcolumnDeleteFromEnd(int column)Deletes all the specified number of columns from the PrecisionMatrix object starting from the end of the PrecisionMatrix objectvoidcolumnDeleteFromStart(int column)Deletes all the specified number of columns from the PrecisionMatrix object from the beginning of the PrecisionMatrix objectstatic PrecisionMatrixcolumnJoin(PrecisionMatrix mat1, PrecisionMatrix mat2)Place the first PrecisionMatrix object side by side with the second one passed as argument to this method.java.math.BigDecimaldeterminant()voidfill()Fills this matrix object with valuesjava.math.BigDecimal[][]getArray()intgetCols()PrecisionMatrixgetColumnMatrix(int column)java.lang.StringgetName()PrecisionMatrixgetRowMatrix(int row)intgetRows()PrecisionMatrixinverse()static booleanisMatrixValue(java.lang.String matrixValue)booleanisSquareMatrix()booleanisSystemOfEquations()static voidmain(java.lang.String[] arg)static voidmdeterm()PrecisionMatrixminor(int i, int j)voidmultiply(PrecisionMatrix matrice)static PrecisionMatrixmultiply(PrecisionMatrix matrice1, PrecisionMatrix matrice2)The operation of matrix multiplication.static PrecisionMatrixpow(PrecisionMatrix mat, int pow)voidrandomFill()Fills the matrix with randomly generated values between 1 and 101.voidrandomFill(int n)Fills the matrix with randomly generated values between 1 and nPrecisionMatrixreduceToTriangularMatrix()voidrowDeleteFromEnd(int numOfRows)Deletes the specified number of rows from the end of the PrecisionMatrix objectvoidrowDeleteFromStart(int numOfRows)Deletes the specified number of rows from the beginning of the PrecisionMatrix objectstatic PrecisionMatrixrowJoin(PrecisionMatrix mat1, PrecisionMatrix mat2)Place the first PrecisionMatrix object side by side with the second one passed as argument to this method.PrecisionMatrixscalarDivide(double scalar)PrecisionMatrixscalarMultiply(double scalar)voidsetArray(java.math.BigDecimal[][] array)voidsetName(java.lang.String name)PrecisionMatrixsolveEquation()Used to solve a system of simultaneous equations placed in this PrecisionMatrix object.static PrecisionMatrixsolveEquation(PrecisionMatrix matrix)Used to solve a system of simultaneous equations placed in the PrecisionMatrix object.PrecisionMatrixsubtract(PrecisionMatrix matrice)java.lang.StringtoString()PrecisionMatrixtranspose()PrecisionMatrixunitMatrix()static PrecisionMatrixunitMatrix(int rowSize, int colSize)static PrecisionMatrixunitMatrix(PrecisionMatrix mat)voidupdate(java.math.BigDecimal value, int row, int column)
-
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(java.lang.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(java.math.BigDecimal[][] array)- Parameters:
array- the data array used to create this PreicionMatrix object
-
PrecisionMatrix
- 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(java.math.BigDecimal[][] array)- Parameters:
array- sets the data of this matrix
-
getArray
public java.math.BigDecimal[][] getArray()- Returns:
- the data of this matrix
-
setName
public void setName(java.lang.String name)- Parameters:
name- set's the simple name used to identify used by the user to label this PrecisionMatrix object.
-
getName
public java.lang.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
- Parameters:
matrice- the matrix to be added to this one. The operation is ( this + matrice )- Returns:
- an array containing the product matrix.
-
subtract
- Parameters:
matrice- the matrix to be subtracted from this one. The operation is ( this - matrice )- Returns:
- an array containing the product matrix.
-
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 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
- 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
- Parameters:
mat- the matrix to raise to a given powerpow- the power to raise this matrix to- Returns:
- the matrix multiplied by itself..pow times
-
unitMatrix
- Returns:
- a unit matrix of the same dimension as this matrix object
-
unitMatrix
- Parameters:
rowSize- the number of rows that the unit matrix will havecolSize- 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
- 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
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 objectmat2- 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(java.math.BigDecimal 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 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 objectmat2- 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
- Returns:
- an upper triangular matrix obtained by row reduction.
-
solveEquation
Used to solve a system of simultaneous equations placed in this PrecisionMatrix object.- Returns:
- a PrecisionMatrix object containing the solution matrix.
-
solveEquation
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
- 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
- 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.
-
mdeterm
public static void mdeterm() -
determinant
public java.math.BigDecimal determinant()- Returns:
- the determinant of this matrix.
-
isMatrixValue
public static boolean isMatrixValue(java.lang.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
- 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
- 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
- Returns:
- the inverse of the PrecisionMatrix as another PrecisionMatrix object.
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the matrix in rows and columns.
-
main
public static void main(java.lang.String[] arg)
-