Class Matrix

java.lang.Object
frc.team_8840_lib.utils.math.Matrix

public class Matrix extends Object
  • 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 matrix
      cols - 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 rows
      j - 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 rows
      j - the column of the value 0 less equal to j less than cols
      value - the value to set
    • initialize

      public void initialize()
      Initialize the matrix.
    • initializeZeros

      public void initializeZeros()
      Initialize the matrix with zeros.
    • add

      public Matrix add(double scalar)
      Add a scalar to each number.
      Parameters:
      scalar - the scalar to add
    • add

      public Matrix add(Matrix matrix)
      Add a matrix to this matrix.
      Parameters:
      matrix - the matrix to add
    • multiply

      public Matrix multiply(Matrix a)
      Multiply this matrix by another matrix.
      Parameters:
      a - the matrix to multiply by
    • multiply

      public Matrix multiply(double a)
      Multiply this matrix by a scalar.
      Parameters:
      a - the scalar to multiply by
    • map

      public Matrix map(MathMap map)
      Map the matrix using a function.
    • transpose

      public Matrix transpose()
      Transpose the matrix.
    • subtract

      public Matrix subtract(double scalar)
      Subtract a scalar from each number.
    • subtract

      public Matrix subtract(Matrix matrix)
      Subtract a matrix from this matrix.
      Parameters:
      matrix - the matrix to subtract
    • subtract

      public static Matrix subtract(Matrix a, Matrix b)
      Subtracts a matrix from another matrix
      Parameters:
      a - the matrix to subtract from
      b - the matrix to subtract
      Returns:
      the difference of the two matrices
    • transpose

      public static Matrix transpose(Matrix a)
      Copy a matrix, but reverse the order of the rows and columns.
      Parameters:
      a - the matrix to copy
      Returns:
      the transposed matrix
    • multiply

      public static Matrix multiply(Matrix a, Matrix b)
      Multiply two matrices together.
      Parameters:
      a - the first matrix
      b - the second matrix
      Returns:
      the product of the two matrices
    • fromArray

      public static Matrix fromArray(double[] x)
      Converts an array to an X by 1 matrix.
      Parameters:
      x - the array to convert
      Returns:
      the converted matrix
    • toArray

      public List<Double> toArray()
      Converts this matrix to an array.
      Returns:
      the array