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
+135Lines changed: 135 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -736,6 +736,141 @@ 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 Cholesky factorization (one-shot 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. It combines Cholesky factorization and the solve step in a single call.
748
+
749
+
Result vector or array `x` returns the exact solution to within numerical precision, provided that the matrix is positive definite.
750
+
An error is returned if the matrix is not positive definite or has incompatible sizes with the right-hand-side.
751
+
Use this routine for one-time solves. For repeated solves with the same matrix but different right-hand sides, use `cholesky` followed by `solve_lower_chol`/`solve_upper_chol` for better performance.
`call `[[stdlib_linalg(module):solve_chol(interface)]]`(a, b, x [, lower, overwrite_a, err])`
763
+
764
+
### Arguments
765
+
766
+
`a`: Shall be a rank-2 `real` or `complex` square array containing the coefficient matrix. It is an `intent(inout)` argument. By default (`overwrite_a=.false.`) its contents are preserved; if `overwrite_a=.true.`, it is used as temporary storage and its contents are destroyed by the call.
767
+
768
+
`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.
769
+
770
+
`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.
771
+
772
+
`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.
773
+
774
+
`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.
775
+
776
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
777
+
778
+
### Return value
779
+
780
+
For a positive definite matrix, returns an array value that represents the solution to the linear system of equations.
781
+
782
+
Raises `LINALG_ERROR` if the matrix is not positive definite.
783
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
784
+
If `err` is not present, exceptions trigger an `error stop`.
785
+
786
+
### Example
787
+
788
+
```fortran
789
+
{!example/linalg/example_solve_chol.f90!}
790
+
```
791
+
792
+
## `solve_lower_chol` - Solves a linear system using pre-computed lower Cholesky factor.
793
+
794
+
### Status
795
+
796
+
Experimental
797
+
798
+
### Description
799
+
800
+
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` with `lower=.true.`).
801
+
802
+
Result vector or array `x` returns the exact solution to within numerical precision, provided that the factorization is correct.
803
+
An error is returned if the matrix and right-hand-side have incompatible sizes.
804
+
The solver is based on LAPACK's `*POTRS` backends.
805
+
806
+
### Syntax
807
+
808
+
`call `[[stdlib_linalg(module):solve_lower_chol(interface)]]`(l, b, x [, err])`
809
+
810
+
### Arguments
811
+
812
+
`l`: Shall be a rank-2 `real` or `complex` square array containing the **lower** Cholesky factor `L` (output of `cholesky(..., lower=.true.)`). It is an `intent(in)` argument.
813
+
814
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `l`, containing the right-hand-side vector(s). It is an `intent(in)` argument.
815
+
816
+
`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.
817
+
818
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
819
+
820
+
### Return value
821
+
822
+
For a correctly factorized matrix, returns an array value that represents the solution to the linear system of equations.
823
+
824
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
825
+
If `err` is not present, exceptions trigger an `error stop`.
826
+
827
+
### Example
828
+
829
+
```fortran
830
+
{!example/linalg/example_solve_lower_chol.f90!}
831
+
```
832
+
833
+
## `solve_upper_chol` - Solves a linear system using pre-computed upper Cholesky factor.
834
+
835
+
### Status
836
+
837
+
Experimental
838
+
839
+
### Description
840
+
841
+
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` with `lower=.false.`).
842
+
843
+
Result vector or array `x` returns the exact solution to within numerical precision, provided that the factorization is correct.
844
+
An error is returned if the matrix and right-hand-side have incompatible sizes.
845
+
The solver is based on LAPACK's `*POTRS` backends.
846
+
847
+
### Syntax
848
+
849
+
`call `[[stdlib_linalg(module):solve_upper_chol(interface)]]`(u, b, x [, err])`
850
+
851
+
### Arguments
852
+
853
+
`u`: Shall be a rank-2 `real` or `complex` square array containing the **upper** Cholesky factor `U` (output of `cholesky(..., lower=.false.)`). It is an `intent(in)` argument.
854
+
855
+
`b`: Shall be a rank-1 or rank-2 array of the same kind as `u`, containing the right-hand-side vector(s). It is an `intent(in)` argument.
856
+
857
+
`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.
858
+
859
+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
860
+
861
+
### Return value
862
+
863
+
For a correctly factorized matrix, returns an array value that represents the solution to the linear system of equations.
864
+
865
+
Raises `LINALG_VALUE_ERROR` if the matrix and rhs vectors have invalid/incompatible sizes.
866
+
If `err` is not present, exceptions trigger an `error stop`.
867
+
868
+
### Example
869
+
870
+
```fortran
871
+
{!example/linalg/example_solve_upper_chol.f90!}
872
+
```
873
+
739
874
## `lstsq` - Computes the least squares solution to a linear matrix equation.
0 commit comments