概要
本サンプルはFortran言語によりLAPACKルーチンZGGEVを利用するサンプルプログラムです。
行列対

及び

入力データ
(本ルーチンの詳細はZGGEV のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10
このデータをダウンロード |
ZGGEV 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
出力結果
(本ルーチンの詳細はZGGEV のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
この出力例をダウンロード |
ZGGEV 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 Eigenvectors (columns): 1 2 3 4 1 1.0000 1.0000 1.0000 1.0000 0.0000 0.0000 0.0000 0.0000 2 0.1600 0.0089 0.0046 0.1600 -0.1200 -0.0067 -0.0034 -0.1200 3 0.1200 -0.0333 0.0629 0.1200 0.1600 -0.0000 0.0000 -0.1600 4 -0.1600 0.0000 -0.0000 0.1600 0.1200 0.1556 0.0629 0.1200
ソースコード
(本ルーチンの詳細はZGGEV のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
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 105 106 107 108 109 110 111 112
このソースコードをダウンロード |
Program zggev_example ! ZGGEV Example Program Text ! Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com ! .. Use Statements .. Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen, & nagf_sort_cmplxvec_rank_rearrange, nagf_sort_realvec_rank Use lapack_interfaces, Only: zggev Use lapack_precision, Only: dp ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Real (Kind=dp), Parameter :: one = 1.0_dp Real (Kind=dp), Parameter :: zero = 0.0_dp Integer, Parameter :: nb = 64, nin = 5, nout = 6 Complex (Kind=dp), Parameter :: cone = (one, zero) ! .. 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(:), & vr(:, :), work(:) Complex (Kind=dp) :: dummy(1, 1) Real (Kind=dp), Allocatable :: rwork(:) Integer, Allocatable :: irank(:) ! .. Intrinsic Procedures .. Intrinsic :: abs, all, epsilon, max, maxloc, nint, real ! .. Executable Statements .. Write (nout, *) 'ZGGEV Example Program Results' 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 zggev('No left vectors', 'Vectors (right)', n, a, lda, b, ldb, & alpha, beta, dummy, 1, vr, ldvr, dummy, lwork, rwork, info) ! Make sure that there is enough workspace for block size nb. lwork = max((nb+1)*n, 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 zggev('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 ZGGEV. INFO =', info Else ! Re-normalize the eigenvectors, largest absolute element real (=1) Do i = 1, n rwork(1:n) = abs(vr(1:n,i)) k = maxloc(rwork(1:n), 1) scal = cone/vr(k, i) vr(1:n, i) = vr(1:n, i)*scal vr(k, i) = cone End Do Write (nout, *) Flush (nout) If (all(abs(beta(1:n))>epsilon(1.0E0_dp))) Then ! Reorder eigenvalues by descending absolute value and print alpha(1:n) = alpha(1:n)/beta(1:n) rwork(1:n) = abs(alpha(1:n)) Allocate (irank(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) ifail = 0 Call nagf_file_print_matrix_complex_gen('Gen', ' ', 1, n, alpha, 1, & 'Eigenvalues:', ifail) ! Reorder eigenvectors accordingly Do j = 1, n beta(1:n) = vr(j, 1:n) Call nagf_sort_cmplxvec_rank_rearrange(beta, 1, n, irank, ifail) vr(j, 1:n) = beta(1:n) End Do Else Write (nout, *) & 'Some of the eigenvalues are infinite or undetermined' 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 Write (nout, *) Flush (nout) ifail = 0 Call nagf_file_print_matrix_complex_gen('Gen', ' ', n, n, vr, ldvr, & 'Eigenvectors (columns):', ifail) End If 100 Format (1X, A, I4) End Program