Package frc.team_8840_lib.utils.math
Class Matrix
java.lang.Object
frc.team_8840_lib.utils.math.Matrix
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(double scalar) Add a scalar to each number.Add a matrix to this matrix.static MatrixfromArray(double[] x) Converts an array to an X by 1 matrix.doubleget(int i, int j) Get a specific value in the matrixintgetCols()Get the number of columns in the matrixdouble[][]getData()Get the data in the matrix as a list of listsintgetRows()Get the number of rows in the matrixvoidInitialize the matrix.voidInitialize the matrix with zeros.Map the matrix using a function.multiply(double a) Multiply this matrix by a scalar.Multiply this matrix by another matrix.static MatrixMultiply two matrices together.voidset(int i, int j, double value) Sets the value at the specified row and columnsubtract(double scalar) Subtract a scalar from each number.Subtract a matrix from this matrix.static MatrixSubtracts a matrix from another matrixtoArray()Converts this matrix to an array.Transpose the matrix.static MatrixCopy a matrix, but reverse the order of the rows and columns.
-
Constructor Details
-
Matrix
public Matrix(int rows, int cols) Creates a new matrix with the specified dimensions. All values are set to a random value between -1 and 1- Parameters:
rows- the number of rows in the matrixcols- the number of columns in the matrix
-
Matrix
public Matrix(int rows, int cols, boolean zeros)
-
-
Method Details
-
getRows
public int getRows()Get the number of rows in the matrix- Returns:
- the number of rows in the matrix
-
getCols
public int getCols()Get the number of columns in the matrix- Returns:
- the number of columns in the matrix
-
getData
public double[][] getData()Get the data in the matrix as a list of lists- Returns:
- the data in the matrix as a list of lists
-
get
public double get(int i, int j) Get a specific value in the matrix- Parameters:
i- the row of the value 0 less equal to i less than rowsj- the column of the value 0 less equal to j less than cols- Returns:
- the value at the specified row and column
-
set
public void set(int i, int j, double value) Sets the value at the specified row and column- Parameters:
i- the row of the value 0 less equal to i less than rowsj- the column of the value 0 less equal to j less than colsvalue- the value to set
-
initialize
public void initialize()Initialize the matrix. -
initializeZeros
public void initializeZeros()Initialize the matrix with zeros. -
add
Add a scalar to each number.- Parameters:
scalar- the scalar to add
-
add
Add a matrix to this matrix.- Parameters:
matrix- the matrix to add
-
multiply
Multiply this matrix by another matrix.- Parameters:
a- the matrix to multiply by
-
multiply
Multiply this matrix by a scalar.- Parameters:
a- the scalar to multiply by
-
map
Map the matrix using a function. -
transpose
Transpose the matrix. -
subtract
Subtract a scalar from each number. -
subtract
Subtract a matrix from this matrix.- Parameters:
matrix- the matrix to subtract
-
subtract
Subtracts a matrix from another matrix- Parameters:
a- the matrix to subtract fromb- the matrix to subtract- Returns:
- the difference of the two matrices
-
transpose
Copy a matrix, but reverse the order of the rows and columns.- Parameters:
a- the matrix to copy- Returns:
- the transposed matrix
-
multiply
Multiply two matrices together.- Parameters:
a- the first matrixb- the second matrix- Returns:
- the product of the two matrices
-
fromArray
Converts an array to an X by 1 matrix.- Parameters:
x- the array to convert- Returns:
- the converted matrix
-
toArray
Converts this matrix to an array.- Returns:
- the array
-