複素一般化非対称固有値問題: 複素非対称行列ペアの一般化固有値 : (オプションで左/右一般化固有ベクトル)

LAPACKサンプルソースコード : 使用ルーチン名:ZGGEV3

ホーム > LAPACKサンプルプログラム目次 > 複素一般化非対称固有値問題 > 複素非対称行列ペアの一般化固有値

概要

本サンプルはFortran言語によりLAPACKルーチンZGGEV3を利用するサンプルプログラムです。

入力データ

(本ルーチンの詳細はZGGEV3 のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10

このデータをダウンロード
ZGGEV3 Example Program Data
  4                                                               : Value of N
  (-21.10,-22.50) ( 53.50,-50.50) (-34.50,127.50) (  7.50,  0.50)
  ( -0.46, -7.78) ( -3.50,-37.50) (-15.50, 58.50) (-10.50, -1.50)
  (  4.30, -5.50) ( 39.70,-17.10) (-68.50, 12.50) ( -7.50, -3.50)
  (  5.50,  4.40) ( 14.40, 43.30) (-32.50,-46.00) (-19.00,-32.50) : End of A
  (  1.00, -5.00) (  1.60,  1.20) ( -3.00,  0.00) (  0.00, -1.00)
  (  0.80, -0.60) (  3.00, -5.00) ( -4.00,  3.00) ( -2.40, -3.20)
  (  1.00,  0.00) (  2.40,  1.80) ( -4.00, -5.00) (  0.00, -3.00)
  (  0.00,  1.00) ( -1.80,  2.40) (  0.00, -4.00) (  4.00, -5.00) : End of B

出力結果

(本ルーチンの詳細はZGGEV3 のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

この出力例をダウンロード
 ZGGEV3 Example Program Results

 Eigenvalues:
             1          2          3          4
 1      3.0000     4.0000     2.0000     3.0000
       -9.0000    -5.0000    -5.0000    -1.0000

 Right Eigenvectors (columns):
          1       2       3       4
 1   0.9449  0.9875  0.9961  0.9449
     0.0000 -0.0000  0.0000  0.0000
 
 2   0.1512  0.0088  0.0046  0.1512
    -0.1134 -0.0066 -0.0034 -0.1134
 
 3   0.1134 -0.0329  0.0626  0.1134
     0.1512 -0.0000  0.0000 -0.1512
 
 4  -0.1512  0.0000 -0.0000  0.1512
     0.1134  0.1536  0.0626  0.1134

ソースコード

(本ルーチンの詳細はZGGEV3 のマニュアルページを参照)

※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

このソースコードをダウンロード
    Program zggev3_example

!     ZGGEV3 Example Program Text

!     Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com

!     .. Use Statements ..
      Use blas_interfaces, Only: dznrm2
      Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen, &
        nagf_sort_cmplxvec_rank_rearrange, nagf_sort_realvec_rank
      Use lapack_interfaces, Only: zggev3
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Complex (Kind=dp) :: scal
      Integer :: i, ifail, info, j, k, lda, ldb, ldvr, lwork, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: a(:, :), alpha(:), b(:, :), beta(:), &
        temp(:), vr(:, :), work(:)
      Complex (Kind=dp) :: dummy(1, 1)
      Real (Kind=dp), Allocatable :: rwork(:)
      Integer, Allocatable :: irank(:)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs, all, conjg, epsilon, maxloc, nint, real
!     .. Executable Statements ..
      Write (nout, *) 'ZGGEV3 Example Program Results'
      Write (nout, *)
      Flush (nout)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n
      lda = n
      ldb = n
      ldvr = n
      Allocate (a(lda,n), alpha(n), b(ldb,n), beta(n), vr(ldvr,n), rwork(8*n))

!     Use routine workspace query to get optimal workspace.
      lwork = -1
      Call zggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &
        alpha, beta, dummy, 1, vr, ldvr, dummy, lwork, rwork, info)

      lwork = nint(real(dummy(1,1)))
      Allocate (work(lwork))

!     Read in the matrices A and B

      Read (nin, *)(a(i,1:n), i=1, n)
      Read (nin, *)(b(i,1:n), i=1, n)

!     Solve the generalized eigenvalue problem

      Call zggev3('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, &
        alpha, beta, dummy, 1, vr, ldvr, work, lwork, rwork, info)

      If (info>0) Then
        Write (nout, *)
        Write (nout, 100) 'Failure in ZGGEV3. INFO =', info
      Else If (all(abs(beta(1:n))>epsilon(1.0E0_dp))) Then
!       Re-normalize the eigenvectors, largest absolute element real
        Do i = 1, n
          rwork(1:n) = abs(vr(1:n,i))
          k = maxloc(rwork(1:n), 1)
          scal = conjg(vr(k,i))/rwork(k)/dznrm2(n, vr(1,i), 1)
          vr(1:n, i) = vr(1:n, i)*scal
        End Do
        alpha(1:n) = alpha(1:n)/beta(1:n)

!       Reorder eigenvalues by descending absolute value
        rwork(1:n) = abs(alpha(1:n))
        Allocate (irank(n), temp(n))
        ifail = 0
        Call nagf_sort_realvec_rank(rwork, 1, n, 'Descending', irank, ifail)
        Call nagf_sort_cmplxvec_rank_rearrange(alpha, 1, n, irank, ifail)

!       Reorder eigenvectors accordingly
        Do j = 1, n
          temp(1:n) = vr(j, 1:n)
          Call nagf_sort_cmplxvec_rank_rearrange(temp, 1, n, irank, ifail)
          vr(j, 1:n) = temp(1:n)
        End Do

        ifail = 0
        Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, alpha, 1, &
          'Eigenvalues:', ifail)
        Write (nout, *)
        Flush (nout)
        Call nagf_file_print_matrix_complex_gen('Gen', ' ', n, n, vr, ldvr, &
          'Right Eigenvectors (columns):', ifail)
      Else
        Write (nout, *) 'Some of the eigenvalues are infinite.'
        Write (nout, *)
        Flush (nout)
        ifail = 0
        Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, alpha, 1, &
          'Alpha', ifail)
        Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, beta, 1, &
          'Beta', ifail)
      End If

100   Format (1X, A, I4)
    End Program


ご案内
関連情報
© 日本ニューメリカルアルゴリズムズグループ株式会社 2025
Privacy Policy  /  Trademarks