forked from rust-ndarray/ndarray-linalg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolveh.rs
More file actions
32 lines (28 loc) · 807 Bytes
/
Copy pathsolveh.rs
File metadata and controls
32 lines (28 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extern crate ndarray;
extern crate ndarray_linalg;
use ndarray::*;
use ndarray_linalg::*;
// Solve `Ax=b` for Hermite matrix A
fn solve() -> Result<(), error::LinalgError> {
let a: Array2<c64> = random_hermite(3); // complex Hermite positive definite matrix
let b: Array1<c64> = random(3);
println!("b = {:?}", &b);
let x = a.solveh(&b)?;
println!("Ax = {:?}", a.dot(&x));
Ok(())
}
// Solve `Ax=b` for many b with fixed A
fn factorize() -> Result<(), error::LinalgError> {
let a: Array2<f64> = random_hpd(3);
let f = a.factorizeh_into()?;
// once factorized, you can use it several times:
for _ in 0..10 {
let b: Array1<f64> = random(3);
let _x = f.solveh_into(b)?;
}
Ok(())
}
fn main() {
solve().unwrap();
factorize().unwrap();
}