|
5 | 5 | //! Solve `A * x = b`: |
6 | 6 | //! |
7 | 7 | //! ``` |
8 | | -//! #[macro_use] |
9 | | -//! extern crate ndarray; |
10 | | -//! extern crate ndarray_linalg; |
11 | | -//! |
12 | 8 | //! use ndarray::prelude::*; |
13 | 9 | //! use ndarray_linalg::Solve; |
14 | | -//! # fn main() { |
15 | 10 | //! |
16 | 11 | //! let a: Array2<f64> = array![[3., 2., -1.], [2., -2., 4.], [-2., 1., -2.]]; |
17 | 12 | //! let b: Array1<f64> = array![1., -2., 0.]; |
18 | 13 | //! let x = a.solve_into(b).unwrap(); |
19 | 14 | //! assert!(x.abs_diff_eq(&array![1., -2., -2.], 1e-9)); |
20 | | -//! |
21 | | -//! # } |
22 | 15 | //! ``` |
23 | 16 | //! |
24 | 17 | //! There are also special functions for solving `A^T * x = b` and |
|
29 | 22 | //! the beginning than solving directly using `A`: |
30 | 23 | //! |
31 | 24 | //! ``` |
32 | | -//! # extern crate ndarray; |
33 | | -//! # extern crate ndarray_linalg; |
34 | | -//! |
35 | 25 | //! use ndarray::prelude::*; |
36 | 26 | //! use ndarray_linalg::*; |
37 | | -//! # fn main() { |
38 | 27 | //! |
39 | | -//! let a: Array2<f64> = random((3, 3)); |
| 28 | +//! /// Use fixed algorithm and seed of PRNG for reproducible test |
| 29 | +//! let mut rng = rand_pcg::Mcg128Xsl64::new(0xcafef00dd15ea5e5); |
| 30 | +//! |
| 31 | +//! let a: Array2<f64> = random_using((3, 3), &mut rng); |
40 | 32 | //! let f = a.factorize_into().unwrap(); // LU factorize A (A is consumed) |
41 | 33 | //! for _ in 0..10 { |
42 | | -//! let b: Array1<f64> = random(3); |
| 34 | +//! let b: Array1<f64> = random_using(3, &mut rng); |
43 | 35 | //! let x = f.solve_into(b).unwrap(); // Solve A * x = b using factorized L, U |
44 | 36 | //! } |
45 | | -//! |
46 | | -//! # } |
47 | 37 | //! ``` |
48 | 38 |
|
49 | 39 | use ndarray::*; |
|
0 commit comments