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
+96Lines changed: 96 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -736,6 +736,102 @@ If `err` is not present, exceptions trigger an `error stop`.
736
736
{!example/linalg/example_solve3.f90!}
737
737
```
738
738
739
+
## `solve_chol` - Solves a linear system using pre-computed Cholesky factors (subroutine interface).
740
+
741
+
### Status
742
+
743
+
Experimental
744
+
745
+
### Description
746
+
747
+
This subroutine computes the solution to a linear matrix equation \( A \cdot x = b \), where \( A \) is a symmetric (or Hermitian) positive definite matrix that has been **previously factorized** using the Cholesky decomposition (via `cholesky`).
748
+
749
+
Result vector or array `x` returns the exact solution to within numerical precision, provided that the factorization is correct.
750
+
An error is returned if the matrix and right-hand-side have incompatible sizes.
751
+
The solver is based on LAPACK's `*POTRS` backends.
`a`: Shall be a rank-2 `real` or `complex` square array containing the Cholesky-factorized matrix (output of `cholesky`). It is an `intent(in)` argument.
760
+
761
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing the right-hand-side vector(s). It is an `intent(in)` argument.
762
+
763
+
`x`: Shall be a rank-1 or rank-2 array of the same kind and size as `b`, that returns the solution(s) to the system. It is an `intent(inout)` argument, and must have the `contiguous` property.
764
+
765
+
`lower`: Shall be an input `logical` flag. If `.true.`, the lower triangular Cholesky factor (`L`) is stored in `a`. If `.false.`, the upper triangular factor (`U`) is stored. This must match the `lower` flag used during the Cholesky factorization. It is a **required**`intent(in)` argument.
766
+
767
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
768
+
769
+
### Return value
770
+
771
+
For a correctly factorized matrix, returns an array value that represents the solution to the linear system of equations.
772
+
773
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
774
+
If `err` is not present, exceptions trigger an `error stop`.
775
+
776
+
### Example
777
+
778
+
```fortran
779
+
{!example/linalg/example_solve_chol.f90!}
780
+
```
781
+
782
+
## `cholesky_solve` - Solves a linear matrix equation using Cholesky factorization (subroutine interface).
783
+
784
+
### Status
785
+
786
+
Experimental
787
+
788
+
### Description
789
+
790
+
This subroutine computes the solution to a linear matrix equation \( A \cdot x = b \), where \( A \) is a symmetric (or Hermitian) positive definite matrix. It combines Cholesky factorization and the solve step in a single call.
791
+
792
+
Result vector or array `x` returns the exact solution to within numerical precision, provided that the matrix is positive definite.
793
+
An error is returned if the matrix is not positive definite or has incompatible sizes with the right-hand-side.
794
+
Use this routine for one-time solves. For repeated solves with the same matrix but different right-hand sides, use `cholesky` followed by `solve_chol` for better performance.
`call `[[stdlib_linalg(module):cholesky_solve(interface)]]`(a, b, x [, lower, overwrite_a, err])`
806
+
807
+
### Arguments
808
+
809
+
`a`: Shall be a rank-2 `real` or `complex` square array containing the coefficient matrix. It is normally an `intent(in)` argument. If `overwrite_a=.true.`, it is an `intent(inout)` argument and is destroyed by the call.
810
+
811
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `a`, containing the right-hand-side vector(s). It is an `intent(in)` argument.
812
+
813
+
`x`: Shall be a rank-1 or rank-2 array of the same kind and size as `b`, that returns the solution(s) to the system. It is an `intent(inout)` argument, and must have the `contiguous` property.
814
+
815
+
`lower` (optional): Shall be an input `logical` flag. If `.true.` (default), the lower triangular Cholesky factorization is computed. If `.false.`, the upper triangular factorization is computed. It is an `intent(in)` argument.
816
+
817
+
`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.
818
+
819
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
820
+
821
+
### Return value
822
+
823
+
For a positive definite matrix, returns an array value that represents the solution to the linear system of equations.
824
+
825
+
Raises `LINALG_ERROR` if the matrix is not positive definite.
826
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
827
+
If `err` is not present, exceptions trigger an `error stop`.
828
+
829
+
### Example
830
+
831
+
```fortran
832
+
{!example/linalg/example_cholesky_solve.f90!}
833
+
```
834
+
739
835
## `lstsq` - Computes the least squares solution to a linear matrix equation.
0 commit comments