pub fn lsqr<T, S>(
matrix: &S,
b: &ArrayView1<'_, T>,
x0: Option<&ArrayView1<'_, T>>,
options: LSQROptions,
) -> SparseResult<LSQRResult<T>>Expand description
LSQR algorithm for sparse least squares problems
Solves the least squares problem min ||Ax - b||_2 or the linear system Ax = b. The method is based on the bidiagonalization of A.
§Arguments
matrix- The coefficient matrix A (m x n)b- The right-hand side vector (length m)x0- Initial guess (optional, length n)options- Solver options
§Returns
An LSQRResult containing the solution and convergence information
§Example
use scirs2_sparse::csr_array::CsrArray;
use scirs2_sparse::linalg::{lsqr, LSQROptions};
use scirs2_core::ndarray::Array1;
// Create an overdetermined system
let rows = vec![0, 0, 1, 1, 2, 2];
let cols = vec![0, 1, 0, 1, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let matrix = CsrArray::from_triplets(&rows, &cols, &data, (3, 2), false).unwrap();
// Right-hand side
let b = Array1::from_vec(vec![1.0, 2.0, 3.0]);
// Solve using LSQR
let result = lsqr(&matrix, &b.view(), None, LSQROptions::default()).unwrap();