pub struct Matrix<F: Field> { /* private fields */ }
Implementations§
Source§impl<F: Field> Matrix<F>
impl<F: Field> Matrix<F>
Sourcepub fn new(matrix: Vec<Vec<F>>) -> Matrix<F>
pub fn new(matrix: Vec<Vec<F>>) -> Matrix<F>
Creates a new matrix from a vector of vectors.
§Example
let a: Matrix<F> = Matrix::new(vec![
vec![F::from(2), F::from(2)],
vec![F::from(3), F::from(4)],
]);
Sourcepub fn is_square(self) -> bool
pub fn is_square(self) -> bool
Returns whether or not the matrix is square.
§Example
let is_square: bool = a.is_square();
assert!(is_square);
Sourcepub fn determinant(self) -> F
pub fn determinant(self) -> F
Sourcepub fn is_diagonal(self) -> bool
pub fn is_diagonal(self) -> bool
Returns whether or not the matrix is diagonal.
§Example
let is_diagonal: bool = a.is_diagonal();
assert!(is_diagonal);
Sourcepub fn is_identity(self) -> bool
pub fn is_identity(self) -> bool
Sourcepub fn ax_b_solve_for_x(self, b: Vec<F>) -> Vec<F>
pub fn ax_b_solve_for_x(self, b: Vec<F>) -> Vec<F>
Solves the system of linear equations Ax = b for x.
§Example
let x: Vec<F> = a.solve_for_x(b);
§Panics
Panics if the matrix is the determinant of the matrix is zero.
§Notes
This function uses the LU decomposition to solve the system of linear equations. The LU decomposition is computed using the Doolittle algorithm.
Sourcepub fn lu_decomposition(&self) -> (Matrix<F>, Matrix<F>)
pub fn lu_decomposition(&self) -> (Matrix<F>, Matrix<F>)
Returns the LU decomposition of the matrix.
§Example
let (l, u): (Matrix<F>, Matrix<F>) = a.lu_decomposition();
§Panics
Panics if the matrix is the determinant of the matrix is zero.
§Notes
This function uses the Doolittle algorithm to compute the LU decomposition. The Doolittle algorithm is a variant of the Gaussian elimination algorithm.
Sourcepub fn scalar_mul(self, scalar: F) -> Matrix<F>
pub fn scalar_mul(self, scalar: F) -> Matrix<F>
Sourcepub fn sum_of_matrix(self) -> F
pub fn sum_of_matrix(self) -> F
Sourcepub fn set_element(&mut self, row: usize, column: usize, new_value: F)
pub fn set_element(&mut self, row: usize, column: usize, new_value: F)
Sets a specific element in the matrix.
§Example
type F = Field;
let a: Matrix<F> = Matrix::new(vec![
vec![F::from(2), F::from(2)],
vec![F::from(3), F::from(4)],
]);
a.set_element(0, 0, F::from(1));
§Panics
Panics if the row or column is out of bounds.
§Notes
This function is equivalent to setting the element in the matrix. With row being the position in the outer vector and column being the position in the inner vector. The first element in the outer vector is row 0 and the first element in the inner vector is column 0.
Sourcepub fn get_element(&self, row: usize, column: usize) -> F
pub fn get_element(&self, row: usize, column: usize) -> F
Gets a specific element in the matrix.
§Example
let a: Matrix<F> = Matrix::new(vec![
vec![F::from(2), F::from(2)],
vec![F::from(3), F::from(4)],
]);
let b: F = a.get_element(0, 0);
assert_eq!(b, F::from(2));
§Panics
Panics if the row or column is out of bounds.
§Notes
This function is equivalent to getting the element in the matrix. With row being the position in the outer vector and column being the position in the inner vector. The first element in the outer vector is row 0 and the first element in the inner vector is column 0.