Class PrecisionMatrix
java.lang.Object
math.matrix.expressParser.PrecisionMatrix
Deals with numbers of higher
precision than Matrix.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BigDecimal[][]
the data array used to create this PrecisionMatrix objectprivate static BigDecimal
attribute used to compute the determinant of the PrecisionMatrix object.private String
The simple name used to label this PrecisionMatrix object. -
Constructor Summary
ConstructorsConstructorDescriptionPrecisionMatrix
(int rows, int cols) PrecisionMatrix
(String name) PrecisionMatrix
(BigDecimal[][] array) PrecisionMatrix
(PrecisionMatrix matrix) -
Method Summary
Modifier and TypeMethodDescriptionprivate static BigDecimal
add
(PrecisionMatrix matrice) void
columnDeleteFromEnd
(int column) Deletes all the specified number of columns from the PrecisionMatrix object starting from the end of the PrecisionMatrix objectvoid
columnDeleteFromStart
(int column) Deletes all the specified number of columns from the PrecisionMatrix object from the beginning of the PrecisionMatrix objectstatic PrecisionMatrix
columnJoin
(PrecisionMatrix mat1, PrecisionMatrix mat2) Place the first PrecisionMatrix object side by side with the second one passed as argument to this method.private static BigDecimal
void
fill()
Fills this matrix object with valuesBigDecimal[][]
getArray()
int
getCols()
getColumnMatrix
(int column) private static BigDecimal
getDet()
getName()
getRowMatrix
(int row) int
getRows()
inverse()
static boolean
isMatrixValue
(String matrixValue) boolean
boolean
static void
static void
mdeterm()
minor
(int i, int j) void
multiply
(PrecisionMatrix matrice) static PrecisionMatrix
multiply
(PrecisionMatrix matrice1, PrecisionMatrix matrice2) The operation of matrix multiplication.static PrecisionMatrix
pow
(PrecisionMatrix mat, int pow) 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 rows from the end of the PrecisionMatrix objectvoid
rowDeleteFromStart
(int numOfRows) Deletes the specified number of rows from the beginning of the PrecisionMatrix objectstatic PrecisionMatrix
rowJoin
(PrecisionMatrix mat1, PrecisionMatrix mat2) Place the first PrecisionMatrix object side by side with the second one passed as argument to this method.scalarDivide
(double scalar) scalarMultiply
(double scalar) void
setArray
(BigDecimal[][] array) private static void
setDet
(BigDecimal det) void
Used to solve a system of simultaneous equations placed in this PrecisionMatrix object.static PrecisionMatrix
solveEquation
(PrecisionMatrix matrix) Used to solve a system of simultaneous equations placed in the PrecisionMatrix object.subtract
(PrecisionMatrix matrice) private static PrecisionMatrix
topRowScalarMultiply
(PrecisionMatrix m, BigDecimal scalar) toString()
static PrecisionMatrix
unitMatrix
(int rowSize, int colSize) static PrecisionMatrix
void
update
(BigDecimal value, int row, int column)
-
Field Details
-
name
The simple name used to label this PrecisionMatrix object. -
array
the data array used to create this PrecisionMatrix object -
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
- 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
- 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
- Parameters:
array
- sets the data of this matrix
-
getArray
- Returns:
- the data of this matrix
-
setDet
- Parameters:
det
- the determinant attribute of objects of this class
-
getDet
- Returns:
- the determinant
-
setName
- Parameters:
name
- set's the simple name used to identify used by the user to label this PrecisionMatrix object.
-
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
- 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.
-
$2X2determinant
- Parameters:
m
- a 2 X 2 matrix- Returns:
- the determinant of this matrix
-
topRowScalarMultiply
- Parameters:
m
- the matrix whose top row is to be multiplied by a scalarscalar
- 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
- Parameters:
m
- the PrecisionMatrix object whose determinant is desired.- Returns:
- the determinant of the matrix
-
determinant
- Returns:
- the determinant of this matrix.
-
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.
-
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
-
main
-