You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/specs/stdlib_linalg.md
+44Lines changed: 44 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -599,3 +599,47 @@ Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and l
599
599
```fortran
600
600
{!example/linalg/example_is_hessenberg.f90!}
601
601
```
602
+
603
+
## `lstsq` - Computes the least squares solution to a linear matrix equation.
604
+
605
+
### Status
606
+
607
+
Experimental
608
+
609
+
### Description
610
+
611
+
This function computes the least-squares solution to a linear matrix equation \( A \cdot x = b \).
612
+
613
+
Result vector `x` returns the approximate solution that minimizes the 2-norm \( || A \cdot x - b ||_2 \), i.e., it contains the least-squares solution to the problem. Matrix `A` may be full-rank, over-determined, or under-determined. The solver is based on LAPACK's `*GELSD` backends.
`a`: Shall be a rank-2 square array containing the coefficient matrix. It is an `intent(inout)` argument.
622
+
623
+
`b`: Shall be a rank-1 array containing the right-hand-side vector. It is an `intent(in)` argument.
624
+
625
+
`cond` (optional): Singular value cut-off threshold for rank evaluation: `s_i >= cond*maxval(s), i=1:rank`. Shall be a scalar, `intent(in)` argument.
626
+
627
+
`overwrite_a` (optional): Shall be an input logical flag. if `.true.`, input matrix a will be used as temporary storage and overwritten. This avoids internal data allocation. This is an `intent(in)` argument.
628
+
629
+
`rank` (optional): Shall be an `integer` scalar value, that contains the rank of input matrix `A`. This is an `intent(out)` argument.
630
+
631
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
632
+
633
+
### Return value
634
+
635
+
Returns an array value that represents the solution to the least squares system.
636
+
637
+
Raises `LINALG_ERROR` if the underlying SVD process did not converge.
638
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
0 commit comments