Struct sparse_complex::ComplexMatrix[][src]

pub struct ComplexMatrix { /* fields omitted */ }

The complex matrix struct

Implementations

impl ComplexMatrix[src]

pub fn new() -> Self[src]

Create a new, initially empty ComplexMatrix

 use sparse_complex::ComplexMatrix;
 let mut m = ComplexMatrix::new();

pub fn from_entries(entries: Vec<(usize, usize, (f64, f64))>) -> Self[src]

Create a new ComplexMatrix from a vector of (row, col, (real, imag)) entries.

 use sparse_complex::ComplexMatrix;
 let entries = vec![(0, 0, (1., 1.)), (1, 1, (1., 1.))];
 let mut m = ComplexMatrix::from_entries(entries);

pub fn add_element(&mut self, row: usize, col: usize, value: (f64, f64))[src]

Add or set an element at location (row, col) with value (real, imag).

pub fn add_elements(&mut self, entries: Vec<(usize, usize, (f64, f64))>)[src]

Add elements correspoding to each triplet (row, col, (real, imag)).

pub fn get(&self, row: usize, col: usize) -> Option<(f64, f64)>[src]

Returns the Element-value at (row, col) if present, or None if not.

 use sparse_complex::ComplexMatrix;
 let entries = vec![(0, 0, (1., -1.)), (1, 1, (-1., 1.))];
 let mut m = ComplexMatrix::from_entries(entries);
 assert_eq!(m.get(2,1), None);
 assert_eq!(m.get(0,0), Some((1., -1.)));
 assert_eq!(m.get(1,1), Some((-1., 1.)));

pub fn solve(
    &mut self,
    b: &[(f64, f64)]
) -> Result<Vec<(f64, f64)>, &'static str>
[src]

Solve the system Ax=b, where:

  • A is a complex matrix
  • b is a complex vector
  • x is the return value.

Returns a Result containing the vector with (real, imag) solutions. Returns an Err if unsuccessful.

This solution use the LU factorization implemented by sparse21.

     use sparse_complex::ComplexMatrix;

     let mut A = ComplexMatrix::new();
     A.add_element(0, 0, (1., 1.));
     A.add_element(1, 1, (1., 1.));

     let b = [(1., 0.), (0., 1.)];

     let solution = A.solve(&b);
     assert_eq!(solution.unwrap(), vec![(0.5, -0.5), (0.5, 0.5)]);

Trait Implementations

impl Clone for ComplexMatrix[src]

impl Debug for ComplexMatrix[src]

impl Default for ComplexMatrix[src]

fn default() -> Self[src]

Returns a 2x2 identity matrix

impl PartialEq<ComplexMatrix> for ComplexMatrix[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.