pub struct ComplexMatrix<T: Float> { /* private fields */ }
Expand description

The complex matrix struct

Implementations

Create a new, initially empty ComplexMatrix

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

Create a new, initially empty ComplexMatrix with a given capacity

 use sparse_complex::ComplexMatrix;
 let mut m = ComplexMatrix::<f64>::with_capacity(5);

Create a new ComplexMatrix from a vector of (row, col, Complex<T>) entries.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 let entries = vec![(0, 0, Complex::new(1., 1.)), (1, 1, Complex::new(1., 1.))];
 let mut m = ComplexMatrix::<f64>::from_entries(entries);

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

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 assert_eq!(m.get(0, 0), Some(&Z1));
 assert_eq!(m.get(1, 1), Some(&Z2));

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

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 assert_eq!(m.get(0, 0), Some(&Z1));
 assert_eq!(m.get(1, 1), Some(&Z2));

Solve the system Ax=b, where:

  • A is a complex matrix
  • b is a complex vector

Returns a Result. Ok(()) if the system was solved successfully, Err(String) if not. The result is stored in b.

The solution use the Eigen::SparseLU.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 let mut b = vec![Complex::new(1., 0.), Complex::new(0., 1.)];
 m.solve(&mut b).unwrap();
 
 let expected = vec![Complex::new(0.5, 0.5), Complex::new(0.5, -0.5)];
 assert_eq!(b, expected);

Solve the system Ax=b, where:

  • A is a complex matrix
  • b is a complex vector

Returns a Result. Ok(()) if the system was solved successfully, Err(String) if not. The result is stored in b.

This solution use the Eigen::SparseLU.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f32> = Complex { re: 1., im: -1. };
 let Z2: Complex<f32> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 let mut b = vec![Complex::new(1., 0.), Complex::new(0., 1.)];
 m.solve(&mut b).unwrap();
 
 let expected = vec![Complex::new(0.5, 0.5), Complex::new(0.5, -0.5)];
 assert_eq!(b, expected);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.