pub fn sqrtm<F>(
a: &ArrayView2<'_, F>,
max_iter: usize,
tol: F,
) -> LinalgResult<Array2<F>>
Expand description
Compute the matrix square root using the Denman-Beavers iteration.
The matrix square root X of matrix A satisfies X^2 = A. This function uses the Denman-Beavers iteration, which is suitable for matrices with no eigenvalues on the negative real axis.
§Arguments
a
- Input square matrix (should be positive definite for real result)max_iter
- Maximum number of iterationstol
- Convergence tolerance
§Returns
- Matrix square root of a
§Examples
use ndarray::array;
use scirs2_linalg::matrix_functions::sqrtm;
let a = array![[4.0_f64, 0.0], [0.0, 9.0]];
let sqrt_a = sqrtm(&a.view(), 20, 1e-10).unwrap();
// sqrt_a should be approximately [[2.0, 0.0], [0.0, 3.0]]
assert!((sqrt_a[[0, 0]] - 2.0).abs() < 1e-10);
assert!((sqrt_a[[0, 1]] - 0.0).abs() < 1e-10);
assert!((sqrt_a[[1, 0]] - 0.0).abs() < 1e-10);
assert!((sqrt_a[[1, 1]] - 3.0).abs() < 1e-10);