計算ルーチン: 実対称三重対角行列もしくはこの形式の複素エルミート行列の全ての固有値 : (そしてオプショナルで固有ベクトル(divide-and-conquer))

LAPACKサンプルソースコード : 使用ルーチン名:ZSTEDC

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > 実対称三重対角行列もしくはこの形式の複素エルミート行列の全ての固有値

概要

本サンプルはFortran言語によりLAPACKルーチンZSTEDCを利用するサンプルプログラムです。

入力データ

(本ルーチンの詳細はZSTEDC のマニュアルページを参照)

このデータをダウンロード
ZSTEDC Example Program Data

    4               2                                      :Values of N and KD

 ( -3.13 , 0.00) (  1.94, -2.10) ( -3.40,  0.25)
                 ( -1.91,  0.00) ( -0.82, -0.89) ( -0.67,  0.34)
                                 ( -2.87,  0.00) ( -2.10, -0.16)
                                                 (  0.50,  0.00) :End matrix A

出力結果

(本ルーチンの詳細はZSTEDC のマニュアルページを参照)

この出力例をダウンロード
 ZSTEDC Example Program Results

 Eigenvalues
     -7.0042           -4.0038            0.5968            3.0012

 Eigenvectors
                    1                 2                 3                 4
 1  ( 0.7293, 0.0000) (-0.2128, 0.1511) (-0.3354,-0.1604) (-0.5114,-0.0163)
 2  (-0.1654,-0.2046) ( 0.7316, 0.0000) (-0.2804,-0.3413) (-0.2374,-0.3796)
 3  ( 0.6081, 0.0301) ( 0.3910,-0.3843) (-0.0144, 0.1532) ( 0.5523,-0.0000)
 4  ( 0.1653,-0.0303) ( 0.2775,-0.1378) ( 0.8019, 0.0000) (-0.4517, 0.1693)

ソースコード

(本ルーチンの詳細はZSTEDC のマニュアルページを参照)

※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。


このソースコードをダウンロード
    Program zstedc_example

!     ZSTEDC 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_comp
      Use lapack_interfaces, Only: zhbtrd, zstedc
      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
      Integer :: i, ifail, info, j, k, kd, ldab, ldz, lgn, liwork, lrwork, &
        lwork, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: ab(:, :), work(:), z(:, :)
      Complex (Kind=dp) :: cdum(1)
      Real (Kind=dp), Allocatable :: d(:), e(:), rwork(:)
      Real (Kind=dp) :: rdum(1)
      Integer :: idum(1)
      Integer, Allocatable :: iwork(:)
      Character (1) :: clabs(1), rlabs(1)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs, ceiling, conjg, log, max, maxloc, min, nint, real
!     .. Executable Statements ..
      Write (nout, *) 'ZSTEDC Example Program Results'
      Write (nout, *)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n, kd
      ldab = kd + 1
      ldz = n
      lgn = ceiling(log(real(n,kind=dp))/log(2.0_dp))
      Allocate (ab(ldab,n), z(ldz,n), d(n), e(n-1))

!     Use routine workspace query to get optimal workspace.
      lwork = -1
      lrwork = -1
      liwork = -1
      Call zstedc('V', n, d, e, z, ldz, cdum, lwork, rdum, lrwork, idum, &
        liwork, info)

!     Make sure that there is enough workspace.
      lwork = max(n*n, nint(real(cdum(1))))
      lrwork = max(1+3*n+2*n*lgn+4*n*n, nint(rdum(1)))
      liwork = max(6+6*n+5*n*lgn, idum(1))
      Allocate (work(lwork), rwork(lrwork), iwork(liwork))

!     Read the upper or lower triangular part of the band matrix A
!     from data file

      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

!     Reduce A to tridiagonal form T = (Z**T)*A*Z, and form Z

      Call zhbtrd('V', uplo, n, kd, ab, ldab, d, e, z, ldz, work, info)

!     Calculate all the eigenvalues and eigenvectors of A,
!     from T and Z

      Call zstedc('V', n, d, e, z, ldz, work, lwork, rwork, lrwork, iwork, &
        liwork, info)

      If (info==0) Then

!       Print eigenvalues and eigenvectors

        Write (nout, *) 'Eigenvalues'
        Write (nout, 100) d(1:n)

        Write (nout, *)
        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_comp('General', ' ', n, n, z, &
          ldz, 'Bracketed', 'F7.4', 'Eigenvectors', 'Integer', rlabs, &
          'Integer', clabs, 80, 0, ifail)

      Else
        Write (nout, 110) 'Failure in ZSTEDC. INFO = ', info
      End If

100   Format (4X, F8.4, 3(10X,F8.4))
110   Format (1X, A, I10)
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks