概要
本サンプルはFortran言語によりLAPACKルーチンZGEEVを利用するサンプルプログラムです。
行列のすべての固有値と右固有ベクトルを求めます。
入力データ
(本ルーチンの詳細はZGEEV のマニュアルページを参照)このデータをダウンロード |
ZGEEV Example Program Data 4 :Value of N (-3.97, -5.04) (-4.11, 3.70) (-0.34, 1.01) ( 1.29, -0.86) ( 0.34, -1.50) ( 1.52, -0.43) ( 1.88, -5.38) ( 3.36, 0.65) ( 3.31, -3.85) ( 2.50, 3.45) ( 0.88, -1.08) ( 0.64, -1.48) (-1.10, 0.82) ( 1.81, -1.59) ( 3.25, 1.33) ( 1.57, -3.44) :End of matrix A
出力結果
(本ルーチンの詳細はZGEEV のマニュアルページを参照)この出力例をダウンロード |
ZGEEV Example Program Results Eigenvalues (-6.0004,-6.9998) (-5.0000, 2.0060) ( 7.9982,-0.9964) ( 3.0023,-3.9998) Eigenvectors 1 2 3 4 1 0.8457 -0.3865 -0.1730 -0.0356 0.0000 0.1732 0.2669 -0.1782 2 -0.0177 -0.3539 0.6924 0.1264 0.3036 0.4529 0.0000 0.2666 3 0.0875 0.6124 0.3324 0.0129 0.3115 0.0000 0.4960 -0.2966 4 -0.0561 -0.0859 0.2504 0.8898 -0.2906 -0.3284 -0.0147 0.0000
ソースコード
(本ルーチンの詳細はZGEEV のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
このソースコードをダウンロード |
Program zgeev_example ! ZGEEV 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 Use lapack_interfaces, Only: zgeev Use lapack_precision, Only: dp ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Integer, Parameter :: nb = 64, nin = 5, nout = 6 ! .. Local Scalars .. Integer :: i, ifail, info, lda, ldvr, lwork, n ! .. Local Arrays .. Complex (Kind=dp), Allocatable :: a(:, :), vr(:, :), w(:), work(:) Complex (Kind=dp) :: dummy(1, 1) Real (Kind=dp), Allocatable :: rwork(:) ! .. Intrinsic Procedures .. Intrinsic :: max, nint, real ! .. Executable Statements .. Write (nout, *) 'ZGEEV Example Program Results' Write (nout, *) ! Skip heading in data file Read (nin, *) Read (nin, *) n lda = n ldvr = n Allocate (a(lda,n), vr(ldvr,n), w(n), rwork(2*n)) ! Use routine workspace query to get optimal workspace. lwork = -1 Call zgeev('No left vectors', 'Vectors (right)', n, a, lda, w, 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 the matrix A from data file Read (nin, *)(a(i,1:n), i=1, n) ! Compute the eigenvalues and right eigenvectors of A Call zgeev('No left vectors', 'Vectors (right)', n, a, lda, w, dummy, 1, & vr, ldvr, work, lwork, rwork, info) If (info==0) Then ! Print solution Write (nout, *) 'Eigenvalues' Write (nout, 100) w(1:n) Write (nout, *) 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_complex_gen('General', ' ', n, n, vr, & ldvr, 'Eigenvectors', ifail) Else Write (nout, *) Write (nout, 110) 'Failure in ZGEEV. INFO = ', info End If 100 Format ((3X,4(' (',F7.4,',',F7.4,')',:))) 110 Format (1X, A, I4) End Program