Skip to content

Commit ed45fb5

Browse files
committed
Specs for constrained_lstsq
1 parent b306f91 commit ed45fb5

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,55 @@ This subroutine computes the internal working space requirements for the least-s
860860

861861
`lcwork` (`complex` `a`, `b`): For a `complex` system, shall be an `integer` scalar, that returns the minimum array size required for the `complex` working storage to this system.
862862

863+
## `constrained_lstsq` - Compute the solution of the equality-constrained least-squares problem {#constrained-lstsq}
864+
865+
### Status
866+
867+
Experimental
868+
869+
### Description
870+
871+
This function computes the solution \(x\) of the equality-constrained linear least-squares problem
872+
$$
873+
\begin{aligned}
874+
\mathrm{minimize} & \quad \| Ax - b \|^2 \\
875+
\mathrm{subject~to} & \quad Cx = d,
876+
\end{aligned}
877+
$$
878+
where \(A\) is an \( m \times n \) matrix (with \(m \geq n\)) and \(C\) a \( p \times n\) matrix (with \(p \leq n\)). The solver is based on LAPACK's `*GLSE` backends.
879+
880+
### Syntax
881+
882+
`x = ` [[stdlib_linalg(module):constrained_lstsq(interface)]] `(A, b, C, d[, overwrite_matrices, err])`
883+
884+
### Arguments
885+
886+
`a`: Shall be a rank-2 `real` or `complex` array used in the definition of the least-squares cost. It is an `intent(inout)` argument.
887+
888+
`b`: Shall be a rank-1 array of the same kind as `a` appearing in the definition of the least-squares cost. It is an `intent(inout)` argument.
889+
890+
`c`: Shall be a rank-2 `real` or `complex` array of the same kind as `a` defining the linear equality constraints. It is an `intent(inout)` argument.
891+
892+
`d`: Shall be a rank-1 array of the same kind as `a` appearing in the definition of the linear equality constraints.
893+
894+
`overwrite_matrices` (optional): Shall be an input `logical` flag. If `.true.`, the input matrices and vectors will be overwritten during the computation of the solution. It is an `intent(in)` argument.
895+
896+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
897+
898+
### Return value
899+
900+
Returns an array of the same kind as `a` containing the solution of the equality constrained least-squares problem.
901+
902+
Raises `LINALG_ERROR` if the underlying constrained least-squares solver did not converge.
903+
Raises `LINALG_VALUE_ERROR` if the matrices and vectors have invalid/incompatible dimensions.
904+
Exceptions trigger an `error stop`.
905+
906+
### Example
907+
908+
```fortran
909+
{!example/linalg/example_constrained_lstsq1.f90!}
910+
```
911+
863912
## `det` - Computes the determinant of a square matrix
864913

865914
### Status

src/stdlib_linalg.fypp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ module stdlib_linalg
590590
!! subject to Cx = d
591591
!!
592592
!! where A is of size `m x n` and C of size `p x n`.
593-
!! ([Specification]())
593+
!! ([Specification](../page/specs/stdlib_linalg.html#constrained-lstsq))
594594
!!
595595
!! ### Description
596596
!!

0 commit comments

Comments
 (0)