Crates.io | sparse_complex |
lib.rs | sparse_complex |
version | 0.1.4 |
source | src |
created_at | 2021-03-11 15:41:40.120344 |
updated_at | 2022-06-09 02:02:20.914148 |
description | A simple solver for complex sparse matrices. |
homepage | |
repository | https://github.com/felipemarkson/sparse_complex |
max_upload_size | |
id | 367335 |
size | 848,580 |
An simple solver for sparse complex linear systems based on Eigen::SparseLU.
We use num::Complex
Lets consider the complex linear system bellow:
$$ \begin{bmatrix} 1 - j1 & 0\ 0 & -1 + j1 \end{bmatrix} \begin{bmatrix} x_1 \ x_2 \end{bmatrix}= \begin{bmatrix} 1 \ j1 \end{bmatrix} $$
We can solve this system as follows:
use num::Complex;
use sparse_complex::ComplexMatrix;
let mut m = ComplexMatrix::<f64>::new();
m.add_element(0, 0, Complex { re: 1., im: -1. });
m.add_element(1, 1, Complex { re: -1., im: 1. });
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);
The solution of this system is:
$$ \frac{1}{2} \begin{bmatrix} 1 + j1 \ 1 - j1 \end{bmatrix} $$
The sparse_complex
crate is tested for rustc
1.61 and greater.
MIT License. See LICENSE.
sparse_complex
also depends on Eigen v3.4.0 which is licensed under MPL v2.0. The source code of Eigen can be found on Eigen's Home Page.