File: example_eigvals_generalized.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 (26 lines) | stat: -rw-r--r-- 801 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
! Eigenvalues of a general real/complex matrix for the generalized eigenproblem
program example_eigvals_generalized
  use stdlib_linalg, only: eigvals, eye
  implicit none

  real, allocatable :: A(:,:), B(:,:), lambda(:)
  complex, allocatable :: cA(:,:), cB(:,:), clambda(:)

  ! NB Fortran is column-major -> transpose input
  A = transpose(reshape([ [2, 8, 4], &
                          [1, 3, 5], &
                          [9, 5,-2] ], [3,3]))

  B = eye(3)

  ! Real generalized eigenproblem
  lambda = eigvals(A, B)
  print *, 'Real generalized matrix eigenvalues: ', lambda

  ! Complex generalized eigenproblem
  cA = cmplx(A, -2*A)
  cB = cmplx(B, 0.5*B)
  clambda = eigvals(cA, cB)
  print *, 'Complex generalized matrix eigenvalues: ', clambda

end program example_eigvals_generalized