Skip to content

Commit db90b37

Browse files
committed
document inv
1 parent bf0dfd3 commit db90b37

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,39 @@ If `err` is not present, exceptions trigger an `error stop`.
971971
```fortran
972972
{!example/linalg/example_inverse3.f90!}
973973
```
974+
975+
## `inv` - Inverse of a square matrix.
976+
977+
### Status
978+
979+
Experimental
980+
981+
### Description
982+
983+
This function returns the inverse of a square `real` or `complex` matrix in-place.
984+
The inverse, \( A^{-1} \), is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
985+
986+
The solver is based on LAPACK's `*GETRF` and `*GETRI` backends.
987+
988+
### Syntax
989+
990+
`b ` [[stdlib_linalg(module):inv(interface)]] `(a, [, err])`
991+
992+
### Arguments
993+
994+
`a`: Shall be a rank-2, square, `real` or `complex` array containing the coefficient matrix. It is an `intent(inout)` argument.
995+
996+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
997+
998+
### Return value
999+
1000+
Returns an array value of the same type, kind and rank as `a`, that contains the inverse matrix \(A^{-1}\).
1001+
1002+
Raises `LINALG_ERROR` if the matrix is singular or has invalid size.
1003+
If `err` is not present, exceptions trigger an `error stop`.
1004+
1005+
### Example
1006+
1007+
```fortran
1008+
{!example/linalg/example_inverse2.f90!}
1009+
```

src/stdlib_linalg.fypp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,26 @@ module stdlib_linalg
557557

558558
! Function interface
559559
interface inv
560+
!! version: experimental
561+
!!
562+
!! Inverse of a square matrix
563+
!! ([Specification](../page/specs/stdlib_linalg.html#inv-inverse-of-a-square-matrix))
564+
!!
565+
!!### Summary
566+
!! This interface provides methods for computing the inverse of a square `real` or `complex` matrix.
567+
!! The inverse \( A^{-1} \) is defined such that \( A \cdot A^{-1} = A^{-1} \cdot A = I_n \).
568+
!!
569+
!!### Description
570+
!!
571+
!! This function interface provides methods that return the inverse of a square matrix.
572+
!! Supported data types include `real` and `complex`.
573+
!! The inverse matrix \( A^{-1} \) is returned as a function result.
574+
!! Exceptions are raised in case of singular matrix or invalid size, and trigger an `error stop` if
575+
!! the state flag `err` is not provided.
576+
!!
577+
!!@note The provided functions are intended for square matrices.
578+
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
579+
!!
560580
#:for rk,rt,ri in RC_KINDS_TYPES
561581
#:if rk!="xdp"
562582
module function stdlib_linalg_inverse_${ri}$(a,err) result(inva)
@@ -584,7 +604,7 @@ module stdlib_linalg
584604
!!
585605
!!### Description
586606
!!
587-
!! This operator interface provides a convenient way to compute the inverse of a matrix.
607+
!! This subroutine interface provides a way to compute the inverse of a matrix in-place.
588608
!! Supported data types include `real` and `complex`.
589609
!! On completion, matrix `a` is replaced by the inverse matrix. Pre-allocated storage may be provided
590610
!! for the array of pivot indices, `pivot`. If all pre-allocated work spaces are provided, no internal

0 commit comments

Comments
 (0)