Skip to content

Commit 72893d9

Browse files
committed
Add example/solveh.rs
1 parent 69b80b7 commit 72893d9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/solveh.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
extern crate ndarray;
3+
extern crate ndarray_linalg;
4+
5+
use ndarray::*;
6+
use ndarray_linalg::*;
7+
8+
// Solve `Ax=b` for Hermite matrix A
9+
fn solve() -> Result<(), error::LinalgError> {
10+
let a: Array2<c64> = random_hermite(3); // complex Hermite positive definite matrix
11+
let b: Array1<c64> = random(3);
12+
println!("b = {:?}", &b);
13+
let f = a.factorizeh()?; // DK factorize
14+
let x = f.solveh(b)?;
15+
println!("Ax = {:?}", a.dot(&x));;
16+
Ok(())
17+
}
18+
19+
// Solve `Ax=b` for many b with fixed A
20+
fn factorize() -> Result<(), error::LinalgError> {
21+
let a: Array2<f64> = random_hpd(3);
22+
let f = a.factorizeh_into()?;
23+
// once factorized, you can use it several times:
24+
for _ in 0..10 {
25+
let b: Array1<f64> = random(3);
26+
let _x = f.solveh(b)?;
27+
}
28+
Ok(())
29+
}
30+
31+
fn main() {
32+
solve().unwrap();
33+
factorize().unwrap();
34+
}

0 commit comments

Comments
 (0)