-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
40 lines (37 loc) · 1.08 KB
/
main.rs
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
33
34
35
36
37
38
39
40
//! # examples::main
//!
//! A simple demonstration of using this library.
#![warn(missing_docs)]
use rmatrix_ks::{
matrix::{
complex::{is_hermitian_matrix, moore_penrose_inverse},
matrix::Matrix,
},
number::instances::{complex::Complex, float::Float},
};
fn main() {
// Properties that the Moore-Penrose inverse must satisfy.
let rect = Matrix::<Complex<Float>>::of(
2,
3,
&[
(1.0, 2.0),
(2.0, -1.0),
(3.0, 0.0),
(4.0, 0.0),
(5.0, 1.0),
(6.0, -2.0),
]
.map(|(r, i)| Complex::of(Float::of(r), Float::of(i))),
)
.unwrap();
let rectp = moore_penrose_inverse(&rect);
// A . Ap . A = A
assert_eq!(rect.clone() * rectp.clone() * rect.clone(), rect);
// Ap . A . Ap = Ap
assert_eq!(rectp.clone() * rect.clone() * rectp.clone(), rectp);
// A . Ap is a hermitian matrix.
assert!(is_hermitian_matrix(&(rect.clone() * rectp.clone())));
// Ap . A is also a hermitian matrix.
assert!(is_hermitian_matrix(&(rectp * rect)));
}