Package maxharold.matrix
Class Matrix
java.lang.Object
maxharold.matrix.Matrix
Class used for creating matrices and performing matrix operations
-
Constructor Summary
ConstructorsConstructorDescriptionMatrix(double[] vector) Constructs a Matrix from an array that acts as a row vectorMatrix(double[][] raw) Constructs a Matrix from a 2D array (makes the matrix null if invalid)Matrix(int rows, int cols) Constructs an empty matrix of a specified sizeConstructs a matrix from specified rows as vectors (makes the matrix null if invalid) -
Method Summary
Modifier and TypeMethodDescriptionstatic MatrixAdds one matrix to anotherdet()Method that calculate the determinant of a square matrixdouble[]getCol(int i) Returns a column of the matrix as an arrayintgetCols()Method that returns the number of columns in the matrixgetElement(int row, int col) Returns the element in a certain row and column of the matrixdouble[]getRow(int i) Returns a row of the matrix as an arrayintgetRows()Method that returns the number of rows in the matrixPerforms hadamard product of two matrices with the current instance of the matrix as the first onestatic MatrixhadamardProduct(Matrix m1, Matrix m2) Performs hadamard product of two matricesSubtracts one matrix from another with the current matrix instance as the first matrixPerforms matrix multiplication with the current matrix instance as the first matrixstatic MatrixPerforms matrix multiplication on two matricesAdds one matrix to another with the current matrix instance as the first matrixvoidsetElement(double val, int i, int j) Sets the value of one of the elements of the matrix (does nothing if coordinates are invalid)static MatrixSubtracts one matrix from anotherT()Transposes the current matrixtoString()Converts the matrix to a string formatPuts current matrix through matrix multiplication with a column vector
-
Constructor Details
-
Matrix
public Matrix(double[][] raw) Constructs a Matrix from a 2D array (makes the matrix null if invalid)- Parameters:
raw- The 2D array that contains the matrix
-
Matrix
public Matrix(double[] vector) Constructs a Matrix from an array that acts as a row vector- Parameters:
vector- The array that represents the row vector
-
Matrix
public Matrix(int rows, int cols) Constructs an empty matrix of a specified size- Parameters:
rows- The number of rows of the matrixcols- The number of columns of the matrix
-
Matrix
Constructs a matrix from specified rows as vectors (makes the matrix null if invalid)- Parameters:
rows- the vectors that make up the rows
-
-
Method Details
-
getRows
public int getRows()Method that returns the number of rows in the matrix- Returns:
- the number of rows
-
getCols
public int getCols()Method that returns the number of columns in the matrix- Returns:
- the number of columns in the matrix
-
getRow
public double[] getRow(int i) Returns a row of the matrix as an array- Parameters:
i- The i-th row of the matrix- Returns:
- The i-th row of the matrix as an array (returns null if invalid)
-
getCol
public double[] getCol(int i) Returns a column of the matrix as an array- Parameters:
i- i-th column of the matrix- Returns:
- The i-th column of the matrix as an array (returns null if invalid)
-
getElement
Returns the element in a certain row and column of the matrix- Parameters:
row- The row the desired element lies incol- The column the desired element lies in- Returns:
- The desired element of the matrix (returns null if invalid)
-
setElement
public void setElement(double val, int i, int j) Sets the value of one of the elements of the matrix (does nothing if coordinates are invalid)- Parameters:
val- The replacing valuei- The i-th row the value lies inj- The i-th column the value lies in
-
transformVector
Puts current matrix through matrix multiplication with a column vector- Parameters:
v- the vector- Returns:
- the transformed vector (returns null if invalid)
-
mul
Performs matrix multiplication on two matrices- Parameters:
m1- The first matrixm2- The second matrix- Returns:
- m1 * m2 (returns null if invalid)
-
mul
Performs matrix multiplication with the current matrix instance as the first matrix- Parameters:
m2- The second matrix- Returns:
- m1 * m2 (returns null if invalid)
-
add
Adds one matrix to another- Parameters:
m1- the first matrixm2- the second matrix- Returns:
- m1 + m2 (returns null if invalid)
-
plus
Adds one matrix to another with the current matrix instance as the first matrix- Parameters:
m2- the second matrix- Returns:
- current_matrix + m2 (returns null if invalid)
-
subtract
Subtracts one matrix from another- Parameters:
m1- the first matrixm2- the second matrix- Returns:
- m1 - m2 (returns null if invalid)
-
minus
Subtracts one matrix from another with the current matrix instance as the first matrix- Parameters:
m2- the second matrix- Returns:
- current_matrix - m2 (returns null if invalid)
-
hadamardProduct
Performs hadamard product of two matrices- Parameters:
m1- the first matrixm2- the second matrix- Returns:
- m1 ⊙ m2 (returns null if invalid)
-
hadamardProduct
Performs hadamard product of two matrices with the current instance of the matrix as the first one- Parameters:
m2- the second matrix- Returns:
- current_matrix ⊙ m2 (returns null if invalid)
-
det
Method that calculate the determinant of a square matrix- Returns:
- the determinant (returns null if matrix is not square)
-
T
Transposes the current matrix- Returns:
- the transposed matrix
-
toString
Converts the matrix to a string format
-