Skip to content

Commit 04a61b7

Browse files
committed
add example
1 parent 48de116 commit 04a61b7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

example/linalg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ADD_EXAMPLE(lapack_getrf)
2929
ADD_EXAMPLE(lstsq1)
3030
ADD_EXAMPLE(lstsq2)
3131
ADD_EXAMPLE(norm)
32+
ADD_EXAMPLE(mnorm)
3233
ADD_EXAMPLE(get_norm)
3334
ADD_EXAMPLE(solve1)
3435
ADD_EXAMPLE(solve2)

example/linalg/example_mnorm.f90

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
program example_mnorm
2+
use stdlib_linalg, only: mnorm
3+
use stdlib_kinds, only: sp
4+
implicit none
5+
real(sp) :: a(3,3), na
6+
real(sp) :: b(3,3,4), nb(4) ! Array of 4 3x3 matrices
7+
8+
! Initialize example matrix
9+
a = reshape([1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 3])
10+
11+
! Compute Euclidean norm of single matrix
12+
na = mnorm(a, 'Euclidean')
13+
print *, "Euclidean norm of matrix a:", na
14+
15+
! Initialize array of matrices
16+
b(:,:,1) = a
17+
b(:,:,2) = 2*a
18+
b(:,:,3) = 3*a
19+
b(:,:,4) = 4*a
20+
21+
! Compute infinity norm of each 3x3 matrix in b
22+
nb = mnorm(b, 'inf', dim=[1,2])
23+
print *, "Infinity norms of matrices in b:", nb
24+
end program example_mnorm

0 commit comments

Comments
 (0)