概要
本サンプルはFortran言語によりLAPACKルーチンZHBEVを利用するサンプルプログラムです。
エルミート帯行列のすべての固有値と固有ベクトルを求めます。
計算された固有値と固有ベクトルの誤差限界近似値も合わせて求めます。
入力データ
(本ルーチンの詳細はZHBEV のマニュアルページを参照)1 2 3 4 5 6 7 8 9
このデータをダウンロード |
ZHBEV Example Program Data 5 2 :Values of N and KD (1.0, 0.0) (2.0,-1.0) (3.0,-1.0) (2.0, 0.0) (3.0,-2.0) (4.0,-2.0) (3.0, 0.0) (4.0,-3.0) (5.0,-3.0) (4.0, 0.0) (5.0,-4.0) (5.0, 0.0) :End of matrix A
出力結果
(本ルーチンの詳細はZHBEV のマニュアルページを参照)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
この出力例をダウンロード |
ZHBEV Example Program Results Eigenvalues -6.4185 -1.4094 1.4421 4.4856 16.9002 Eigenvectors 1 2 3 4 5 1 -0.2534 0.6367 -0.2560 0.0171 0.1051 -0.0538 0.0000 0.3721 0.5500 -0.0983 2 -0.0662 -0.2578 0.5344 -0.2608 0.2516 0.4301 0.2413 0.0000 0.4869 -0.1789 3 0.5274 -0.3039 -0.4245 -0.0399 0.4994 0.0000 -0.3481 0.0915 0.2142 -0.1513 4 0.1061 0.3450 0.4964 -0.0253 0.5611 -0.4981 -0.0832 -0.1546 -0.1700 0.0000 5 -0.4519 -0.2469 -0.1979 0.5614 0.4837 0.0424 0.2634 -0.1114 -0.0000 0.2509 Error estimate for the eigenvalues 3.8E-15 Error estimates for the eigenvectors 7.5E-16 1.3E-15 1.3E-15 1.2E-15 3.0E-16
ソースコード
(本ルーチンの詳細はZHBEV のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
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
このソースコードをダウンロード |
Program zhbev_example ! ZHBEV 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 Use lapack_interfaces, Only: ddisna, zhbev Use lapack_precision, Only: dp ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Integer, Parameter :: nin = 5, nout = 6 Character (1), Parameter :: uplo = 'U' ! .. Local Scalars .. Complex (Kind=dp) :: scal Real (Kind=dp) :: eerrbd, eps Integer :: i, ifail, info, j, k, kd, ldab, ldz, n ! .. Local Arrays .. Complex (Kind=dp), Allocatable :: ab(:, :), work(:), z(:, :) Real (Kind=dp), Allocatable :: rcondz(:), rwork(:), w(:), zerrbd(:) ! .. Intrinsic Procedures .. Intrinsic :: abs, conjg, epsilon, max, maxloc, min ! .. Executable Statements .. Write (nout, *) 'ZHBEV Example Program Results' Write (nout, *) ! Skip heading in data file Read (nin, *) Read (nin, *) n, kd ldab = kd + 1 ldz = n Allocate (ab(ldab,n), work(n), z(ldz,n), rcondz(n), rwork(3*n-2), w(n), & zerrbd(n)) ! Read the upper or lower triangular part of the symmetric band ! matrix A from data file If (uplo=='U') Then Read (nin, *)((ab(kd+1+i-j,j),j=i,min(n,i+kd)), i=1, n) Else If (uplo=='L') Then Read (nin, *)((ab(1+i-j,j),j=max(1,i-kd),i), i=1, n) End If ! Solve the band Hermitian eigenvalue problem Call zhbev('Vectors', uplo, n, kd, ab, ldab, w, z, ldz, work, rwork, & info) If (info==0) Then ! Print solution Write (nout, *) 'Eigenvalues' Write (nout, 100) w(1:n) Flush (nout) ! Normalize the eigenvectors, largest element real Do i = 1, n rwork(1:n) = abs(z(1:n,i)) k = maxloc(rwork(1:n), 1) scal = conjg(z(k,i))/abs(z(k,i))/dznrm2(n, z(1,i), 1) z(1:n, i) = z(1:n, i)*scal End Do ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 Call nagf_file_print_matrix_complex_gen('General', ' ', n, n, z, ldz, & 'Eigenvectors', ifail) ! 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))) ! Call DDISNA to estimate reciprocal condition ! numbers for the eigenvectors Call ddisna('Eigenvectors', n, n, w, rcondz, info) ! Compute the error estimates for the eigenvectors Do i = 1, n zerrbd(i) = eerrbd/rcondz(i) End Do ! Print the approximate error bounds for the eigenvalues ! and vectors Write (nout, *) Write (nout, *) 'Error estimate for the eigenvalues' Write (nout, 110) eerrbd Write (nout, *) Write (nout, *) 'Error estimates for the eigenvectors' Write (nout, 110) zerrbd(1:n) Else Write (nout, 120) 'Failure in ZHBEV. INFO =', info End If 100 Format (3X, (8F8.4)) 110 Format (4X, 1P, 6E11.1) 120 Format (1X, A, I4) End Program