2018-01-17 23:48:47 +08:00
|
|
|
#![cfg(feature = "arbitrary")]
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
use na::{Matrix4, Matrix4x5};
|
|
|
|
|
|
|
|
fn unzero_diagonal(a: &mut Matrix4<f64>) {
|
2018-10-22 13:00:10 +08:00
|
|
|
for i in 0..4 {
|
2017-08-03 01:37:44 +08:00
|
|
|
if a[(i, i)] < 1.0e-7 {
|
|
|
|
a[(i, i)] = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
quickcheck! {
|
|
|
|
fn solve_lower_triangular(a: Matrix4<f64>, b: Matrix4x5<f64>) -> bool {
|
|
|
|
let mut a = a;
|
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.lower_triangle();
|
|
|
|
let x = a.solve_lower_triangular(&b).unwrap();
|
|
|
|
|
|
|
|
println!("{}\n{}\n{}\n{}", tri, x, tri * x, b);
|
|
|
|
|
|
|
|
relative_eq!(tri * x, b, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn solve_upper_triangular(a: Matrix4<f64>, b: Matrix4x5<f64>) -> bool {
|
|
|
|
let mut a = a;
|
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.upper_triangle();
|
|
|
|
let x = a.solve_upper_triangular(&b).unwrap();
|
|
|
|
|
|
|
|
println!("{}\n{}\n{}\n{}", tri, x, tri * x, b);
|
|
|
|
|
|
|
|
relative_eq!(tri * x, b, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tr_solve_lower_triangular(a: Matrix4<f64>, b: Matrix4x5<f64>) -> bool {
|
|
|
|
let mut a = a;
|
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.lower_triangle();
|
|
|
|
let x = a.tr_solve_lower_triangular(&b).unwrap();
|
|
|
|
|
|
|
|
println!("{}\n{}\n{}\n{}", tri, x, tri * x, b);
|
|
|
|
|
|
|
|
relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tr_solve_upper_triangular(a: Matrix4<f64>, b: Matrix4x5<f64>) -> bool {
|
|
|
|
let mut a = a;
|
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.upper_triangle();
|
|
|
|
let x = a.tr_solve_upper_triangular(&b).unwrap();
|
|
|
|
|
|
|
|
println!("{}\n{}\n{}\n{}", tri, x, tri * x, b);
|
|
|
|
|
|
|
|
relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
}
|