pub struct ComplexMatrix<T: Float> { /* private fields */ }
Expand description
The complex matrix struct
Implementations§
Source§impl<T: Float> ComplexMatrix<T>
impl<T: Float> ComplexMatrix<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, initially empty ComplexMatrix
use sparse_complex::ComplexMatrix;
let mut m = ComplexMatrix::<f64>::new();
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new, initially empty ComplexMatrix
with a given capacity
use sparse_complex::ComplexMatrix;
let mut m = ComplexMatrix::<f64>::with_capacity(5);
Sourcepub fn from_entries(entries: Vec<(usize, usize, Complex<T>)>) -> Self
pub fn from_entries(entries: Vec<(usize, usize, Complex<T>)>) -> Self
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);
Sourcepub fn add_element(&mut self, row: usize, col: usize, value: Complex<T>)
pub fn add_element(&mut self, row: usize, col: usize, value: Complex<T>)
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));
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&Complex<T>>
pub fn get(&self, row: usize, col: usize) -> Option<&Complex<T>>
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));
Source§impl ComplexMatrix<f64>
impl ComplexMatrix<f64>
Sourcepub fn solve(&self, b: &mut [Complex<f64>]) -> Result<(), &'static str>
pub fn solve(&self, b: &mut [Complex<f64>]) -> Result<(), &'static str>
Solve the system Ax=b
, where:
A
is a complex matrixb
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);
Source§impl ComplexMatrix<f32>
impl ComplexMatrix<f32>
Sourcepub fn solve(&self, b: &mut [Complex<f32>]) -> Result<(), &'static str>
pub fn solve(&self, b: &mut [Complex<f32>]) -> Result<(), &'static str>
Solve the system Ax=b
, where:
A
is a complex matrixb
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§
Source§impl<T: Clone + Float> Clone for ComplexMatrix<T>
impl<T: Clone + Float> Clone for ComplexMatrix<T>
Source§fn clone(&self) -> ComplexMatrix<T>
fn clone(&self) -> ComplexMatrix<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreimpl<T: Float> StructuralPartialEq for ComplexMatrix<T>
Auto Trait Implementations§
impl<T> Freeze for ComplexMatrix<T>
impl<T> RefUnwindSafe for ComplexMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for ComplexMatrix<T>where
T: Send,
impl<T> Sync for ComplexMatrix<T>where
T: Sync,
impl<T> Unpin for ComplexMatrix<T>where
T: Unpin,
impl<T> UnwindSafe for ComplexMatrix<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more