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
+124Lines changed: 124 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -600,6 +600,130 @@ Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and l
600
600
{!example/linalg/example_is_hessenberg.f90!}
601
601
```
602
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 `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
622
+
623
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing one or more right-hand-side vector(s), each in its leading dimension. It is an `intent(in)` argument.
624
+
625
+
`cond` (optional): Shall be a scalar `real` 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 of the same kind and rank as `b`, containing the solution(s) to the least squares system.
636
+
637
+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
638
+
Raises `LINALG_VALUE_ERROR` if the matrix and right-hand-side vector have invalid/incompatible sizes.
639
+
Exceptions trigger an `error stop`.
640
+
641
+
### Example
642
+
643
+
```fortran
644
+
{!example/linalg/example_lstsq1.f90!}
645
+
```
646
+
647
+
## `solve_lstsq` - Compute the least squares solution to a linear matrix equation (subroutine interface).
648
+
649
+
### Status
650
+
651
+
Experimental
652
+
653
+
### Description
654
+
655
+
This subroutine computes the least-squares solution to a linear matrix equation \( A \cdot x = b \).
656
+
657
+
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 `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
666
+
667
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing one or more right-hand-side vector(s), each in its leading dimension. It is an `intent(in)` argument.
668
+
669
+
`x`: Shall be an array of same kind and rank as `b`, containing the solution(s) to the least squares system. It is an `intent(inout)` argument.
670
+
671
+
`real_storage` (optional): Shall be a `real` rank-1 array of the same kind `a`, providing working storage for the solver. It minimum size can be determined with a call to [[stdlib_linalg(module):lstsq_space(interface)]]. It is an `intent(inout)` argument.
672
+
673
+
`int_storage` (optional): Shall be an `integer` rank-1 array, providing working storage for the solver. It minimum size can be determined with a call to [[stdlib_linalg(module):lstsq_space(interface)]]. It is an `intent(inout)` argument.
674
+
675
+
`cmpl_storage` (optional): For `complex` systems, it shall be a `complex` rank-1 array, providing working storage for the solver. It minimum size can be determined with a call to [[stdlib_linalg(module):lstsq_space(interface)]]. It is an `intent(inout)` argument.
676
+
677
+
`cond` (optional): Shall be a scalar `real` value cut-off threshold for rank evaluation: `s_i >= cond*maxval(s), i=1:rank`. Shall be a scalar, `intent(in)` argument.
678
+
679
+
`singvals` (optional): Shall be a `real` rank-1 array of the same kind `a` and size at least `minval(shape(a))`, returning the list of singular values `s(i)>=cond*maxval(s)`, in descending order of magnitude. It is an `intent(out)` argument.
680
+
681
+
`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.
682
+
683
+
`rank` (optional): Shall be an `integer` scalar value, that contains the rank of input matrix `A`. This is an `intent(out)` argument.
684
+
685
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
686
+
687
+
### Return value
688
+
689
+
Returns an array value that represents the solution to the least squares system.
690
+
691
+
Raises `LINALG_ERROR` if the underlying Singular Value Decomposition process did not converge.
692
+
Raises `LINALG_VALUE_ERROR` if the matrix and right-hand-side vector have invalid/incompatible sizes.
693
+
Exceptions trigger an `error stop`.
694
+
695
+
### Example
696
+
697
+
```fortran
698
+
{!example/linalg/example_lstsq2.f90!}
699
+
```
700
+
701
+
## `lstsq_space` - Compute internal working space requirements for the least squares solver.
702
+
703
+
### Status
704
+
705
+
Experimental
706
+
707
+
### Description
708
+
709
+
This subroutine computes the internal working space requirements for the least-squares solver, [[stdlib_linalg(module):solve_lstsq(interface)]] .
`a`: Shall be a rank-2 `real` or `complex` array containing the linear system coefficient matrix. It is an `intent(in)` argument.
718
+
719
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing the system's right-hand-side vector(s). It is an `intent(in)` argument.
720
+
721
+
`lrwork`: Shall be an `integer` scalar, that returns the minimum array size required for the `real` working storage to this system.
722
+
723
+
`liwork`: Shall be an `integer` scalar, that returns the minimum array size required for the `integer` working storage to this system.
724
+
725
+
`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.
726
+
603
727
## `det` - Computes the determinant of a square matrix
0 commit comments