Skip to content

Commit 4089d18

Browse files
committed
Specs + example.
1 parent d8b1857 commit 4089d18

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

doc/specs/stdlib_linalg.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,3 +1880,37 @@ If `err` is not present, exceptions trigger an `error stop`.
18801880
{!example/linalg/example_mnorm.f90!}
18811881
```
18821882

1883+
## `expm` - Computes the matrix exponential {#expm}
1884+
1885+
### Status
1886+
1887+
Experimental
1888+
1889+
### Description
1890+
1891+
Given a matrix \(A\), this function compute its matrix exponential \(E = \exp(A)\) using a Pade approximation.
1892+
1893+
### Syntax
1894+
1895+
`E = ` [[stdlib_linalg(module):expm(interface)]] `(a [, order, err])`
1896+
1897+
### Arguments
1898+
1899+
`a`: Shall be a rank-2 `real` or `complex` array containing the data. It is an `intent(in)` argument.
1900+
1901+
`order` (optional): Shall be a non-negative `integer` value specifying the order of the Pade approximation. By default `order=10`. It is an `intent(in)` argument.
1902+
1903+
`err` (optional): Shall be a `type(linalg_state_type)` value. This is an `intent(out)` argument.
1904+
### Return value
1905+
1906+
The returned array `E` contains the Pade approximation of \(\exp(A)\).
1907+
1908+
If `A` is non-square or `order` is negative, it raise a `LINALG_VALUE_ERROR`.
1909+
If `err` is not present, exceptions trigger an `error stop`.
1910+
1911+
### Example
1912+
1913+
```fortran
1914+
{!example/linalg/example_expm.f90!}
1915+
```
1916+

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ ADD_EXAMPLE(qr)
5252
ADD_EXAMPLE(qr_space)
5353
ADD_EXAMPLE(cholesky)
5454
ADD_EXAMPLE(chol)
55+
ADD_EXAMPLE(expm)

example/linalg/example_expm.f90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
program example_expm
2+
use stdlib_linalg, only: expm
3+
implicit none
4+
real :: A(3, 3), E(3, 3)
5+
A = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
6+
E = expm(A)
7+
end program example_expm

src/stdlib_linalg.fypp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ module stdlib_linalg
16841684
!! version : experimental
16851685
!!
16861686
!! Computes the exponential of a matrix using a rational Pade approximation.
1687+
!! ([Specification](../page/specs/stdlib_linalg.html#expm))
16871688
!!
16881689
!! ### Description
16891690
!!

0 commit comments

Comments
 (0)