Skip to content

Commit ac1e0f9

Browse files
committed
implement examples
1 parent 91a4e36 commit ac1e0f9

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

example/linalg/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ ADD_EXAMPLE(svd)
2727
ADD_EXAMPLE(svdvals)
2828
ADD_EXAMPLE(determinant)
2929
ADD_EXAMPLE(determinant2)
30+
ADD_EXAMPLE(cholesky)
31+
ADD_EXAMPLE(chol)

example/linalg/example_chol.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Cholesky factorization: function interface
2+
program example_chol
3+
use stdlib_linalg, only: chol
4+
implicit none
5+
6+
real, allocatable, dimension(:,:) :: A,L,U
7+
8+
! Set real matrix
9+
A = reshape( [ [6, 15, 55], &
10+
[15, 55, 225], &
11+
[55, 225, 979] ], [3,3] )
12+
13+
! Decompose (lower)
14+
L = chol(A, lower=.true.)
15+
16+
! Compare decomposition
17+
print *, maxval(abs(A-matmul(L,transpose(L))))
18+
19+
! Decompose (upper)
20+
U = chol(A, lower=.false.)
21+
22+
! Compare decomposition
23+
print *, maxval(abs(A-matmul(transpose(U),U)))
24+
25+
end program example_chol

example/linalg/example_cholesky.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Cholesky factorization: subroutine interface
2+
program example_cholesky
3+
use stdlib_linalg, only: cholesky
4+
implicit none
5+
6+
real, dimension(3,3) :: A,L,U
7+
8+
! Set real matrix
9+
A = reshape( [ [6, 15, 55], &
10+
[15, 55, 225], &
11+
[55, 225, 979] ], [3,3] )
12+
13+
! Decompose (lower)
14+
call cholesky(A, L, lower=.true.)
15+
16+
! Compare decomposition
17+
print *, maxval(abs(A-matmul(L,transpose(L))))
18+
19+
! Decompose (upper)
20+
call cholesky(A, U, lower=.false.)
21+
22+
! Compare decomposition
23+
print *, maxval(abs(A-matmul(transpose(U),U)))
24+
25+
end program example_cholesky

0 commit comments

Comments
 (0)