int vsip_llsqsol_f(const vsip_mview_f* A, const vsip_vview_f* b, const vsip_vview_f* x); int vsip_cllsqsol_f(const vsip_cmview_f* A, const vsip_cvview_f* b, const vsip_cvview_f* x);
This function solves the linear least squares problem:

where
is an
matrix with
,
is an
-dimensional vector, and
is the
-dimensional solution vector that
minimizes the Euclidean norm of the residual vector.
The function uses QR decomposition with column pivoting to solve the least squares problem, which provides a numerically
stable solution even when matrix
is rank-deficient.
const vsip_dmview_p* A: Pointer to the
matrix view of coefficients.
const vsip_dvview_p* b: Pointer to the
-dimensional vector view containing the right-hand side.
const vsip_dvview_p* x: Pointer to the
-dimensional vector view where the least squares solution will be
stored.
Returns 0 on success.
Returns a non-zero value on error (e.g., if matrix dimensions are incompatible or memory allocation fails).
vsip_mview_f *A; // M×N coefficient matrix vsip_vview_f *b; // M-dimensional right-hand side vector vsip_vview_f *x; // N-dimensional solution vector int result; // Assuming A, b, and x have been properly initialized with appropriate dimensions result = vsip_llsqsol_f(A, b, x); if (result != 0) { // Handle error }
The number of rows
in matrix
must be greater than or equal to the number of columns
.
The solution
minimizes the 2-norm of the residual vector
.
If
has full column rank, the solution is unique. If
is rank-deficient, the function returns a basic solution with
at most
non-zero components.
This function is particularly useful for overdetermined systems where there is no exact solution, but a best-fit solution is desired.