File: example_schur_eigvals.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (32 lines) | stat: -rw-r--r-- 900 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
! This example includes eigenvalue computation in addition to 
! the Schur decomposition for a randomly generated matrix.
program example_schur_eigenvalues
  use stdlib_linalg, only: schur
  use stdlib_linalg_constants, only: dp
  implicit none
  
  integer, parameter :: n = 5  
  real(dp), dimension(n,n) :: A, T, Z
  complex(dp), dimension(n) :: eigenvalues
  
  ! Create a random real-valued square matrix
  call random_number(A)

  ! Compute the Schur decomposition and eigenvalues
  call schur(A, T, Z, eigenvalues)

  ! Output results
  print *, "Random Matrix A:"
  print *, A
  print *, "Schur Form Matrix T:"
  print *, T
  print *, "Orthogonal Matrix Z:"
  print *, Z
  print *, "Eigenvalues:"
  print *, eigenvalues

  ! Test factorization: Z*T*Z^T = A
  print *, "Max error in reconstruction:", maxval(abs(matmul(Z, matmul(T, transpose(Z))) - A))

end program example_schur_eigenvalues