概要
本サンプルはFortran言語によりLAPACKルーチンDSBGVXを利用するサンプルプログラムです。
帯対称固有値問題
![$ (0.0, 1.0]$](img/img93.gif)

入力データ
(本ルーチンの詳細はDSBGVX のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12 13 14
このデータをダウンロード |
DSBGVX Example Program Data 4 2 1 :Values of N, KA and KB 0.0 1.0 :Values of VL and VU 0.24 0.39 0.42 -0.11 0.79 0.63 -0.25 0.48 -0.03 :End of matrix A 2.07 0.95 1.69 -0.29 0.65 -0.33 1.17 :End of matrix B
出力結果
(本ルーチンの詳細はDSBGVX のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12
この出力例をダウンロード |
DSBGVX Example Program Results Number of eigenvalues found = 1 Eigenvalues 0.0992 Selected eigenvectors 1 1 0.6729 2 -0.1009 3 0.0155 4 -0.3806
ソースコード
(本ルーチンの詳細はDSBGVX のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
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
このソースコードをダウンロード |
Program dsbgvx_example ! DSBGVX Example Program Text ! Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com ! .. Use Statements .. Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen Use lapack_interfaces, Only: dsbgvx Use lapack_precision, Only: dp ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Real (Kind=dp), Parameter :: zero = 0.0E+0_dp Integer, Parameter :: nin = 5, nout = 6 Character (1), Parameter :: uplo = 'U' ! .. Local Scalars .. Real (Kind=dp) :: abstol, vl, vu Integer :: i, ifail, il, info, iu, j, ka, kb, ldab, ldbb, ldq, ldz, m, n ! .. Local Arrays .. Real (Kind=dp), Allocatable :: ab(:, :), bb(:, :), q(:, :), w(:), & work(:), z(:, :) Integer, Allocatable :: iwork(:), jfail(:) ! .. Intrinsic Procedures .. Intrinsic :: max, min ! .. Executable Statements .. Write (nout, *) 'DSBGVX Example Program Results' Write (nout, *) ! Skip heading in data file Read (nin, *) Read (nin, *) n, ka, kb ldab = ka + 1 ldbb = kb + 1 ldq = n ldz = n m = n Allocate (ab(ldab,n), bb(ldbb,n), q(ldq,n), w(n), work(7*n), z(ldz,m), & iwork(5*n), jfail(n)) ! Read the lower and upper bounds of the interval to be searched, ! and read the upper or lower triangular parts of the matrices A ! and B from data file Read (nin, *) vl, vu If (uplo=='U') Then Read (nin, *)((ab(ka+1+i-j,j),j=i,min(n,i+ka)), i=1, n) Read (nin, *)((bb(kb+1+i-j,j),j=i,min(n,i+kb)), i=1, n) Else If (uplo=='L') Then Read (nin, *)((ab(1+i-j,j),j=max(1,i-ka),i), i=1, n) Read (nin, *)((bb(1+i-j,j),j=max(1,i-kb),i), i=1, n) End If ! Set the absolute error tolerance for eigenvalues. With abstol ! set to zero, the default value is used instead abstol = zero ! Solve the generalized symmetric eigenvalue problem ! A*x = lambda*B*x Call dsbgvx('Vectors', 'Values in range', uplo, n, ka, kb, ab, ldab, bb, & ldbb, q, ldq, vl, vu, il, iu, abstol, m, w, z, ldz, work, iwork, & jfail, info) If (info>=0 .And. info<=n) Then ! Print solution Write (nout, 100) 'Number of eigenvalues found =', m Write (nout, *) Write (nout, *) 'Eigenvalues' Write (nout, 110) w(1:m) Flush (nout) ! ifail: behaviour on error exit ! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft ifail = 0 Call nagf_file_print_matrix_real_gen('General', ' ', n, m, z, ldz, & 'Selected eigenvectors', ifail) If (info>0) Then Write (nout, 100) 'INFO eigenvectors failed to converge, INFO =', & info Write (nout, *) 'Indices of eigenvectors that did not converge' Write (nout, 120) jfail(1:m) End If Else If (info>n .And. info<=2*n) Then i = info - n Write (nout, 130) 'The leading minor of order ', i, & ' of B is not positive definite' Write (nout, 100) 'Failure in DSBGVX. INFO =', info End If 100 Format (1X, A, I5) 110 Format (3X, (8F8.4)) 120 Format (3X, (8I8)) 130 Format (1X, A, I4, A) End Program