Skip to content

Commit 8b138f7

Browse files
committed
add non-in-place subroutine example
1 parent b23c811 commit 8b138f7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ADD_EXAMPLE(is_triangular)
1515
ADD_EXAMPLE(inverse1)
1616
ADD_EXAMPLE(inverse2)
1717
ADD_EXAMPLE(inverse3)
18+
ADD_EXAMPLE(inverse4)
1819
ADD_EXAMPLE(outer_product)
1920
ADD_EXAMPLE(trace)
2021
ADD_EXAMPLE(state1)

example/linalg/example_inverse4.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! Matrix inversion example: subroutine interface
2+
program example_inverse4
3+
use stdlib_linalg_constants, only: dp
4+
use stdlib_linalg, only: invert,eye
5+
implicit none
6+
7+
real(dp) :: A(2,2), Am1(2,2)
8+
9+
! Input matrix (NB Fortran is column major! input columns then transpose)
10+
A = transpose(reshape( [4, 3, &
11+
3, 2], [2,2] ))
12+
13+
! Invert matrix
14+
call invert(A,Am1)
15+
16+
print *, ' |',Am1(1,:),'|' ! | -2 3 |
17+
print *, ' inv(A)= |',Am1(2,:),'|' ! | 3 -4 |
18+
19+
! Final check
20+
print *, 'CHECK passed? ',matmul(A,Am1)==eye(2)
21+
22+
end program example_inverse4

0 commit comments

Comments
 (0)