Struct sparse_complex::ComplexMatrix
source · [−]pub struct ComplexMatrix<T: Float> { /* private fields */ }
Expand description
The complex matrix struct
Implementations
sourceimpl<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));
sourceimpl 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);
sourceimpl 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
sourceimpl<T: Clone + Float> Clone for ComplexMatrix<T>
impl<T: Clone + Float> Clone for ComplexMatrix<T>
sourcefn clone(&self) -> ComplexMatrix<T>
fn clone(&self) -> ComplexMatrix<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Float + Display> Debug for ComplexMatrix<T>
impl<T: Float + Display> Debug for ComplexMatrix<T>
sourceimpl<T: PartialEq + Float> PartialEq<ComplexMatrix<T>> for ComplexMatrix<T>
impl<T: PartialEq + Float> PartialEq<ComplexMatrix<T>> for ComplexMatrix<T>
sourcefn eq(&self, other: &ComplexMatrix<T>) -> bool
fn eq(&self, other: &ComplexMatrix<T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ComplexMatrix<T>) -> bool
fn ne(&self, other: &ComplexMatrix<T>) -> bool
This method tests for !=
.
impl<T: Float> StructuralPartialEq for ComplexMatrix<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more