MatrixUtilities

Struct MatrixUtilities 

Source
pub struct MatrixUtilities<T: Number> { /* private fields */ }
Expand description

MatrixUtilities is a utility struct designed to perform various algorithms or operations for Matrix instances, including adding, subtracting, multiplying, and computing the row and reduced row echelon form of Matrix instances

Implementations§

Source§

impl<T: Number + Neg<Output = T> + One> MatrixUtilities<T>

Source

pub fn append(matrix: Matrix<T>, row: &[T]) -> Matrix<T>

Appends a row to a given Matrix, returning an updated Matrix instance with the newly appended row

§Parameters
  • matrix - The Matrix needed to add a row
  • row: An &[i64] slice
§Returns
  • An updated Matrix object that adds the given row to the given Matrix
Source

pub fn append_multiple(matrix: Matrix<T>, rows: &[&[T]]) -> Matrix<T>

Appends multiple rows to a given Matrix, returning an updated Matrix instance with the newly appended rows

§Parameters
  • matrix: The Matrix needed to add additional rows
  • rows: A slice of &[i64] slices representing a series of rows to add to a given Matrix
§Returns
  • An updated Matrix object that adds all rows to this Matrix
Source

pub fn row_echelon_form(matrix: Matrix<T>) -> Matrix<T>

Computes the row echelon form for the given matrix and returns the result as an updated Matrix instance

§Parameters
  • matrix: The Matrix needed to compute the row echelon form
§Returns
  • A Matrix instance containing the given matrix in row echelon form
Source

pub fn rref(matrix: Matrix<T>) -> Matrix<T>

Computes the reduced row echelon form (RREF) for the given matrix and returns the result as an updated Matrix instance

§Parameters
  • matrix: The Matrix needed to compute the reduced row echelon form
§Returns
  • A Matrix instance containing the given matrix in reduced row echelon form
Source

pub fn gaussian_elimination( matrix: Matrix<T>, ) -> Result<HashMap<char, T>, String>

Performs the Gaussian Elimination technique on a given matrix to solve for its system of equations’ missing variables (e.g. x, y, and z)

§Parameters
  • matrix: The Matrix to perform Gaussian Elimination on
§Returns
  • A Result based on whether the matrix had a solution
    • An Err with an enclosed String representing the error state of solving the matrix using Gaussian Elimination (i.e. no solution or infinitely many solutions)
    • An Ok enclosed with a HashMap containing each variable name mapped to a value with its solution
Source

pub fn add(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>

Adds two Matrix instances together and returns a new Matrix representing their sum

§Parameters
  • a: One Matrix operand addend
  • ‘b’: Another ‘Matrix’ operand addend
§Returns
  • A Result based on whether the two matrices were added or not
    • An Err if the two matrices are different shapes
    • An Ok wrapped inside a Matrix instance that represents the sum of the two matrices a and b
Source

pub fn subtract(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>

Subtracts two Matrix instances together and returns a new Matrix representing their difference

§Parameters
  • a: A Matrix instance that will be one of the operands
  • b: Another ‘Matrix’ instance that will be the second operand to subtract from
§Returns
  • An Result based on whether the two matrices were added
    • An Err value when the two matrices have different shapes
    • An Ok value wrapped with a Matrix instance that represents the difference of the two matrices a and b
Source

pub fn multiply_by_scalar(matrix: Matrix<T>, constant: T) -> Matrix<T>

Multiplies a given Matrix by a given scalar constant

§Parameters
  • matrix: The given Matrix to be multiplied by a scalar constant
  • constant: The given scalar constant to multiply the given Matrix by
§Returns
  • A new Matrix that contains the matrix after multiplying by a scalar constant
Source

pub fn multiply(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>

Multiplies two Matrix instances together and returns their product as a new Matrix object

§Parameters
  • a: One Matrix operand to be multiplied
  • ‘b’: Another Matrix operand to be multiplied
§Returns
  • A Result based on whether the two matrices were multiplied
    • An Err if the columns of Matrix a does not equal the rows of Matrix b
    • An Ok wrapped inside a Matrix object that represents the product between two matrices
Source

pub fn dot(a: Matrix<T>, b: Matrix<T>) -> Result<T, String>

Gets the dot product of two matrices a and b

§Parameters
  • a: One of the Matrix instance operands
  • b: Another Matrix instance operand
§Returns
  • A Result based on whether there is a valid dot product for matrices a and b
    • An Err value if the columns of Matrix ado not equal the rows ofMatrix b
    • An Ok wrapped in a T generic value, representing the dot product
Source

pub fn gauss_jordan_elimination( matrix: Matrix<T>, ) -> Result<HashMap<char, T>, String>

Performs the Gauss-Jordan Elimination technique on a given matrix to solve for the missing variables in a system of equations (e.g. x, y, and z)

§Parameters
  • matrix: The Matrix to perform Gauss-Jordan Elimination on
§Returns
  • A Result based on whether the matrix had a solution
    • An Err with an enclosed String representing the error state of solving the matrix using Gaussian Elimination (i.e. no solution or infinitely many solutions)
    • An Ok enclosed with a HashMap containing each variable name mapped to a value with its solution
Source

pub fn identity(n: usize) -> Matrix<T>

Generates an n by n identity matrix

The identity Matrix is a matrix that when multiplied by another matrix yields that other matrix.

§Returns
  • An n by n identity Matrix
Source

pub fn inverse(matrix: Matrix<T>) -> Result<Matrix<T>, String>

Performs the inverse of a given matrix and returns it as a Matrix instance

§Parameters
  • matrix: The Matrix to perform the inverse on
§Returns
  • A Result type based on whether the given matrix is invertible
    • An Err consisting of a String if the given matrix is not invertible
    • An Ok consisting of the inverse matrix, if the given matrix is invertible
Source

pub fn lu_decomposition( matrix: Matrix<T>, ) -> Result<(Matrix<T>, Matrix<T>), String>

LU Decomposition, or factorization, is a technique used in Linear Algebra to factor a matrix as the product of a lower triangular matrix and an upper triangular matrix. Typically viewed as that of the matrix form of Gaussian Elimination

§Parameters
  • matrix - The matrix to perform LU decomposition on
§Returns
  • A Result type based on whether or not the matrix is invertible
    • Returns an Ok form containing a Matrix tuple containing the l and u decomposed matrices respectively
    • Returns an error if the matrix is not invertible

Auto Trait Implementations§

§

impl<T> Freeze for MatrixUtilities<T>

§

impl<T> RefUnwindSafe for MatrixUtilities<T>
where T: RefUnwindSafe,

§

impl<T> Send for MatrixUtilities<T>
where T: Send,

§

impl<T> Sync for MatrixUtilities<T>
where T: Sync,

§

impl<T> Unpin for MatrixUtilities<T>
where T: Unpin,

§

impl<T> UnwindSafe for MatrixUtilities<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.