Skip to content

Commit 2b2ade9

Browse files
committed
add specs
1 parent 71a1fe5 commit 2b2ade9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,47 @@ Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and l
599599
```fortran
600600
{!example/linalg/example_is_hessenberg.f90!}
601601
```
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.
614+
615+
### Syntax
616+
617+
`x = ` [[stdlib_linalg(module):lstsq(interface)]] `(a, b, [, cond, overwrite_a, rank, err])`
618+
619+
### Arguments
620+
621+
`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.
639+
Exceptions trigger an `error stop`.
640+
641+
### Example
642+
643+
```fortran
644+
{!example/linalg/example_lstsq.f90!}
645+
```

0 commit comments

Comments
 (0)