概要
本サンプルはFortran言語によりLAPACKルーチンDSBEVDを利用するサンプルプログラムです。
対称帯行列の全ての固有値と固有ベクトルを求めます。
DSBEVの例題プログラムは固有値と固有ベクトルの誤差限界計算方法を示します。
入力データ
(本ルーチンの詳細はDSBEVD のマニュアルページを参照)| このデータをダウンロード |
DSBEVD Example Program Data
5 2 :Values of N and KD
'L' :Value of UPLO
1.0
2.0 2.0
3.0 3.0 3.0
4.0 4.0 4.0
5.0 5.0 5.0 :End of matrix A
'V' :Value of JOB
出力結果
(本ルーチンの詳細はDSBEVD のマニュアルページを参照)| この出力例をダウンロード |
DSBEVD Example Program Results
Eigenvalues
-3.2474 -2.6633 1.7511 4.1599 14.9997
Eigenvectors
1 2 3 4 5
1 0.0394 0.6238 0.5635 0.5165 0.1582
2 0.5721 -0.2575 -0.3896 0.5955 0.3161
3 -0.4372 -0.5900 0.4008 0.1470 0.5277
4 -0.4424 0.4308 -0.5581 -0.0470 0.5523
5 0.5332 0.1039 0.2421 -0.5956 0.5400
ソースコード
(本ルーチンの詳細はDSBEVD のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
| このソースコードをダウンロード |
Program dsbevd_example
! DSBEVD 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: dsbevd
Use lapack_precision, Only: dp
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: nin = 5, nout = 6
! .. Local Scalars ..
Integer :: i, ifail, info, j, kd, ldab, ldz, liwork, lwork, n
Character (1) :: job, uplo
! .. Local Arrays ..
Real (Kind=dp), Allocatable :: ab(:, :), w(:), work(:), z(:, :)
Integer, Allocatable :: iwork(:)
! .. Intrinsic Procedures ..
Intrinsic :: max, min
! .. Executable Statements ..
Write (nout, *) 'DSBEVD Example Program Results'
! Skip heading in data file
Read (nin, *)
Read (nin, *) n, kd
ldab = kd + 1
ldz = n
liwork = 5*n + 3
lwork = 2*n*n + 5*n + 1
Allocate (ab(ldab,n), w(n), work(lwork), z(ldz,n), iwork(liwork))
! Read A from data file
Read (nin, *) uplo
If (uplo=='U') Then
Do i = 1, n
Read (nin, *)(ab(kd+1+i-j,j), j=i, min(n,i+kd))
End Do
Else If (uplo=='L') Then
Do i = 1, n
Read (nin, *)(ab(1+i-j,j), j=max(1,i-kd), i)
End Do
End If
Read (nin, *) job
! Calculate all the eigenvalues and eigenvectors of A
Call dsbevd(job, uplo, n, kd, ab, ldab, w, z, ldz, work, lwork, iwork, &
liwork, info)
Write (nout, *)
If (info>0) Then
Write (nout, *) 'Failure to converge.'
Else
! Print eigenvalues and eigenvectors
Write (nout, *) 'Eigenvalues'
Write (nout, 100) w(1:n)
Write (nout, *)
Flush (nout)
! Standardize the eigenvectors so that first elements are non-negative.
Do i = 1, n
If (z(1,i)<0.0_dp) Then
z(1:n, i) = -z(1:n, i)
End If
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_real_gen('General', ' ', n, n, z, ldz, &
'Eigenvectors', ifail)
End If
100 Format (3X, (8F8.4))
End Program
