Skip to content

Commit cff995d

Browse files
committed
add docs
1 parent 5d52d48 commit cff995d

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,76 @@ Specifically, upper Hessenberg matrices satisfy `a_ij = 0` when `j < i-1`, and l
595595
```fortran
596596
{!example/linalg/example_is_hessenberg.f90!}
597597
```
598+
599+
## `det` - Computes the determinant of a square matrix
600+
601+
### Status
602+
603+
Experimental
604+
605+
### Description
606+
607+
This function computes the determinant of a real square matrix.
608+
609+
This interface comes with a `pure` version `det(a)`, and a non-pure version `det(a,overwrite_a,err)` that
610+
allows for more expert control.
611+
612+
### Syntax
613+
614+
`c = ` [[stdlib_linalg(module):det(interface)]] `(a,overwrite_a,err)`
615+
616+
### Arguments
617+
618+
`a`: Shall be a rank-2 square array
619+
620+
`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.
621+
622+
`err` (optional): Shall be a `type(linalg_state_type)` return value.
623+
624+
### Return value
625+
626+
Returns a real scalar value that represents the determinnt of the matrix.
627+
628+
Raises `LINALG_ERROR` if the matrix is singular.
629+
Raises `LINALG_VALUE_ERROR` if the matrix is non-square.
630+
Exceptions are returned to the `err` argument if provided; an `error stop` is triggered otherwise.
631+
632+
### Example
633+
634+
```fortran
635+
{!example/linalg/example_determinant.f90!}
636+
```
637+
638+
## `.det.` - Determinant operator of a square matrix
639+
640+
### Status
641+
642+
Experimental
643+
644+
### Description
645+
646+
This operator returns the determinant of a real square matrix.
647+
648+
This interface is equivalent to the `pure` version of determinant [[stdlib_linalg(module):det(interface)]].
649+
650+
### Syntax
651+
652+
`c = ` [[stdlib_linalg(module):operator(.det.)(interface)]] `(a)`
653+
654+
### Arguments
655+
656+
`a`: Shall be a rank-2 square array
657+
658+
### Return value
659+
660+
Returns a real scalar value that represents the determinnt of the matrix.
661+
662+
Raises `LINALG_ERROR` if the matrix is singular.
663+
Raises `LINALG_VALUE_ERROR` if the matrix is non-square.
664+
Exceptions trigger an `error stop`.
665+
666+
### Example
667+
668+
```fortran
669+
{!example/linalg/example_determinant2.f90!}
670+
```

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ ADD_EXAMPLE(state2)
1919
ADD_EXAMPLE(blas_gemv)
2020
ADD_EXAMPLE(lapack_getrf)
2121
ADD_EXAMPLE(determinant)
22+
ADD_EXAMPLE(determinant2)
2223

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
program example_determinant2
2+
use stdlib_kinds, only: dp
3+
use stdlib_linalg, only: operator(.det.)
4+
implicit none
5+
6+
real(dp) :: d
7+
8+
! Compute determinate of a real matrix
9+
d = .det.reshape([real(dp)::1,2,3,4],[2,2])
10+
11+
print *, d ! a*d-b*c = -2.0
12+
13+
end program example_determinant2

0 commit comments

Comments
 (0)