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>
impl<T: Number + Neg<Output = T> + One> MatrixUtilities<T>
Sourcepub fn append_multiple(matrix: Matrix<T>, rows: &[&[T]]) -> Matrix<T>
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: TheMatrixneeded to add additionalrowsrows: A slice of&[i64]slices representing a series of rows to add to a givenMatrix
§Returns
- An updated
Matrixobject that adds allrowsto thisMatrix
Sourcepub fn row_echelon_form(matrix: Matrix<T>) -> Matrix<T>
pub fn row_echelon_form(matrix: Matrix<T>) -> Matrix<T>
Sourcepub fn gaussian_elimination(
matrix: Matrix<T>,
) -> Result<HashMap<char, T>, String>
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: TheMatrixto perform Gaussian Elimination on
§Returns
- A
Resultbased on whether the matrix had a solution- An
Errwith an enclosedStringrepresenting the error state of solving thematrixusing Gaussian Elimination (i.e. no solution or infinitely many solutions) - An
Okenclosed with aHashMapcontaining each variable name mapped to a value with its solution
- An
Sourcepub fn add(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>
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: OneMatrixoperand addend- ‘b’: Another ‘Matrix’ operand addend
§Returns
- A
Resultbased on whether the two matrices were added or not- An
Errif the two matrices are different shapes - An
Okwrapped inside aMatrixinstance that represents the sum of the two matricesaandb
- An
Sourcepub fn subtract(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>
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: AMatrixinstance that will be one of the operandsb: Another ‘Matrix’ instance that will be the second operand to subtract from
§Returns
- An
Resultbased on whether the two matrices were added- An
Errvalue when the two matrices have different shapes - An
Okvalue wrapped with aMatrixinstance that represents the difference of the two matricesaandb
- An
Sourcepub fn multiply_by_scalar(matrix: Matrix<T>, constant: T) -> Matrix<T>
pub fn multiply_by_scalar(matrix: Matrix<T>, constant: T) -> Matrix<T>
Sourcepub fn multiply(a: Matrix<T>, b: Matrix<T>) -> Result<Matrix<T>, String>
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: OneMatrixoperand to be multiplied- ‘b’: Another
Matrixoperand to be multiplied
§Returns
- A
Resultbased on whether the two matrices were multiplied- An
Errif the columns ofMatrixa does not equal the rows ofMatrixb - An
Okwrapped inside aMatrixobject that represents the product between two matrices
- An
Sourcepub fn dot(a: Matrix<T>, b: Matrix<T>) -> Result<T, String>
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 theMatrixinstance operandsb: AnotherMatrixinstance operand
§Returns
- A
Resultbased on whether there is a valid dot product for matricesaandb- An
Errvalue if the columns ofMatrixado not equal the rows ofMatrixb - An
Okwrapped in a T generic value, representing the dot product
- An
Sourcepub fn gauss_jordan_elimination(
matrix: Matrix<T>,
) -> Result<HashMap<char, T>, String>
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: TheMatrixto perform Gauss-Jordan Elimination on
§Returns
- A
Resultbased on whether the matrix had a solution- An
Errwith an enclosedStringrepresenting the error state of solving thematrixusing Gaussian Elimination (i.e. no solution or infinitely many solutions) - An
Okenclosed with aHashMapcontaining each variable name mapped to a value with its solution
- An
Sourcepub fn identity(n: usize) -> Matrix<T>
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
nbynidentityMatrix
Sourcepub fn inverse(matrix: Matrix<T>) -> Result<Matrix<T>, String>
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: TheMatrixto perform the inverse on
§Returns
- A
Resulttype based on whether the givenmatrixis invertible- An
Errconsisting of aStringif the givenmatrixis not invertible - An
Okconsisting of the inverse matrix, if the givenmatrixis invertible
- An
Sourcepub fn lu_decomposition(
matrix: Matrix<T>,
) -> Result<(Matrix<T>, Matrix<T>), String>
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
Resulttype based on whether or not thematrixis invertible- Returns an Ok form containing a
Matrixtuple containing thelandudecomposed matrices respectively - Returns an error if the
matrixis not invertible
- Returns an Ok form containing a