mymatrix

Struct Matrix

Source
pub struct Matrix { /* private fields */ }
Expand description

Matrix with fractions as elements.

Implementations§

Source§

impl Matrix

Source

pub fn new() -> Self

Create a new matrix object.

Source

pub fn create(row: usize, col: usize, value: Fraction) -> Self

Create a row x col matrix with all identical elements.

Source

pub fn zeros(row: usize, col: usize) -> Self

Create a row x col matrix with all 0 elements.

Source

pub fn ones(row: usize, col: usize) -> Self

Create a row x col matrix with all 1 elements.

Source

pub fn identity(n: usize) -> Self

Generate an n-order identity matrix.

Source

pub fn row_size(&self) -> usize

Return the number of rows in the matrix.

Source

pub fn col_size(&self) -> usize

Return the number of columns in the matrix.

Source

pub fn is_empty(&self) -> bool

Returns true if the matrix contains no elements.

Source

pub fn is_symmetric(&self) -> bool

Returns true if the matrix is symmetric.

Source

pub fn is_upper(&self) -> bool

Check if the matrix is upper triangular matrix.

Source

pub fn is_lower(&self) -> bool

Check if the matrix is lower triangular matrix.

Source

pub fn is_diagonal(&self) -> bool

Check if the matrix is diagonal matrix.

Source

pub fn trace(&self) -> Fraction

Calculate the trace of the matrix.

Source

pub fn transpose(&self) -> Self

Returns the transpose of the matrix.

Source

pub fn row_echelon_form(&self) -> Self

Transform this matrix to general row echelon form.

Source

pub fn row_canonical_form(&self) -> Self

Transform this matrix to reduced row echelon form.

Source

pub fn det(&self) -> Fraction

Calculate the determinant of this matrix.

Source

pub fn submatrix(&self, i: usize, j: usize) -> Self

Return the matrix that removed the i-th row and j-th column, 0 <= i, j < n.

Source

pub fn minor(&self) -> Self

Return the minor matrix.

Source

pub fn cofactor(&self) -> Self

Return the cofactor matrix.

Source

pub fn adj(&self) -> Self

Return the adjugate matrix.

Source

pub fn inv(&self) -> Option<Self>

Calculate the inverse of this matrix.

Source

pub fn rank(&self) -> usize

Calculate the rank of this matrix.

Source

pub fn lu_decomposition(&self) -> (Self, Self)

LU decomposition, use Doolittle algorithm.

Source

pub fn split_row(&self, n: usize) -> (Self, Self)

Split this matrix by rows.

Source

pub fn split_col(&self, n: usize) -> (Self, Self)

Split this matrix by columns.

Source

pub fn expand_row(&mut self, matrix: Self) -> &Self

Expand this matrix by rows.

Source

pub fn expand_col(&mut self, matrix: Self) -> &Self

Expand this matrix by columns.

Source

pub fn e_row_swap(&mut self, i: usize, j: usize) -> &Self

Elementary Row Operations: Row Swap. (A[i] <=> A[j])

Source

pub fn e_scalar_multiplication(&mut self, i: usize, k: Fraction) -> &Self

Elementary Row Operations: Scalar Multiplication. (A[i] *= k)

Source

pub fn e_row_sum(&mut self, i: usize, j: usize, k: Fraction) -> &Self

Elementary Row Operations: Row Sum. (A[i] += A[j] * k)

Trait Implementations§

Source§

impl Add<&Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Matrix) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Matrix> for Matrix

Source§

type Output = Matrix

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Matrix) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Matrix

Source§

type Output = Matrix

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<&Matrix> for Matrix

Source§

fn add_assign(&mut self, rhs: &Matrix)

Performs the += operation. Read more
Source§

impl AddAssign for Matrix

Source§

fn add_assign(&mut self, rhs: Matrix)

Performs the += operation. Read more
Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Matrix

Source§

fn default() -> Matrix

Returns the “default value” for a type. Read more
Source§

impl Display for Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const R: usize, const C: usize> From<[[Fraction; C]; R]> for Matrix

Source§

fn from(value: [[Fraction; C]; R]) -> Self

Converts to this type from the input type.
Source§

impl<const R: usize, const C: usize> From<[[i32; C]; R]> for Matrix

Source§

fn from(value: [[i32; C]; R]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Vec<Fraction>>> for Matrix

Source§

fn from(value: Vec<Vec<Fraction>>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Vec<i32>>> for Matrix

Source§

fn from(value: Vec<Vec<i32>>) -> Self

Converts to this type from the input type.
Source§

impl Hash for Matrix

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for Matrix

Source§

type Output = Vector

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Matrix

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoIterator for Matrix

Source§

type Item = Vector

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Matrix as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Mul<&Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Matrix> for Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Fraction> for Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Fraction) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Matrix> for Fraction

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Matrix> for i32

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<i32> for Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i32) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Matrix

Source§

type Output = Matrix

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign<Fraction> for Matrix

Source§

fn mul_assign(&mut self, rhs: Fraction)

Performs the *= operation. Read more
Source§

impl MulAssign<i32> for Matrix

Source§

fn mul_assign(&mut self, rhs: i32)

Performs the *= operation. Read more
Source§

impl PartialEq for Matrix

Source§

fn eq(&self, other: &Matrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<&Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Matrix) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Matrix> for Matrix

Source§

type Output = Matrix

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Matrix) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Matrix> for &Matrix

Source§

type Output = Matrix

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Matrix

Source§

type Output = Matrix

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<&Matrix> for Matrix

Source§

fn sub_assign(&mut self, rhs: &Matrix)

Performs the -= operation. Read more
Source§

impl SubAssign for Matrix

Source§

fn sub_assign(&mut self, rhs: Matrix)

Performs the -= operation. Read more
Source§

impl Eq for Matrix

Source§

impl StructuralPartialEq for Matrix

Auto Trait Implementations§

§

impl Freeze for Matrix

§

impl RefUnwindSafe for Matrix

§

impl Send for Matrix

§

impl Sync for Matrix

§

impl Unpin for Matrix

§

impl UnwindSafe for Matrix

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V