複素エルミート固有値問題: パック形式のエルミート行列 : (全ての固有値およびオプショナルで固有ベクトル)

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

概要

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

エルミート行列のすべての固有値を求めます。

\begin{displaymath}
A = \left(
\begin{array}{cccc}
1 & 2 - i & 3 - i & 4 - i ...
... 4 - 3i \\
4 + i & 4 + 2i & 4 + 3i & 4
\end{array} \right),
\end{displaymath}

計算された固有値の誤差限界近似値もあわせて求めます。

入力データ

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

このデータをダウンロード
ZHPEV Example Program Data

  4                                                :Value of N

 (1.0, 0.0)  (2.0, -1.0)  (3.0, -1.0)  (4.0, -1.0)
             (2.0,  0.0)  (3.0, -2.0)  (4.0, -2.0)
                          (3.0,  0.0)  (4.0, -3.0)
                                       (4.0,  0.0) :End of matrix A

出力結果

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

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

 Eigenvalues
    -4.2443 -0.6886  1.1412 13.7916

 Error estimate for the eigenvalues
        3.1E-15

ソースコード

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

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

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

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

!     ZHPEV Example Program Text

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

!     .. Use Statements ..
      Use lapack_interfaces, Only: zhpev
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
      Character (1), Parameter :: uplo = 'U'
!     .. Local Scalars ..
      Real (Kind=dp) :: eerrbd, eps
      Integer :: i, info, j, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: ap(:), work(:)
      Complex (Kind=dp) :: dummy(1, 1)
      Real (Kind=dp), Allocatable :: rwork(:), w(:)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs, epsilon, max
!     .. Executable Statements ..
      Write (nout, *) 'ZHPEV Example Program Results'
      Write (nout, *)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n

      Allocate (ap((n*(n+1))/2), work(2*n-1), rwork(3*n-2), w(n))

!     Read the upper or lower triangular part of the matrix A from
!     data file

      If (uplo=='U') Then
        Read (nin, *)((ap(i+(j*(j-1))/2),j=i,n), i=1, n)
      Else If (uplo=='L') Then
        Read (nin, *)((ap(i+((2*n-j)*(j-1))/2),j=1,i), i=1, n)
      End If

!     Solve the Hermitian eigenvalue problem

      Call zhpev('No vectors', uplo, n, ap, w, dummy, 1, work, rwork, info)

      If (info==0) Then

!       Print solution

        Write (nout, *) 'Eigenvalues'
        Write (nout, 100) w(1:n)

!       Get the machine precision, EPS and compute the approximate
!       error bound for the computed eigenvalues.  Note that for
!       the 2-norm, max( abs(W(i)) ) = norm(A), and since the
!       eigenvalues are returned in ascending order
!       max( abs(W(i)) ) = max( abs(W(1)), abs(W(n)))

        eps = epsilon(1.0E0_dp)
        eerrbd = eps*max(abs(w(1)), abs(w(n)))

!       Print the approximate error bound for the eigenvalues

        Write (nout, *)
        Write (nout, *) 'Error estimate for the eigenvalues'
        Write (nout, 110) eerrbd
      Else
        Write (nout, 120) 'Failure in ZHPEV. INFO =', info
      End If

100   Format (3X, (8F8.4))
110   Format (4X, 1P, 6E11.1)
120   Format (1X, A, I4)
    End Program


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