計算ルーチン: 複素一般行列から集客された複素上ヘッセンベルグ行列の固有値とシュール分解の計算

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

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > 複素一般行列から集客された複素上ヘッセンベルグ行列の固有値とシュール分解の計算

概要

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

入力データ

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

このデータをダウンロード
ZHSEQR Example Program Data
  4                                                             :Value of N
 (-3.9700,-5.0400) (-1.1318,-2.5693) (-4.6027,-0.1426) (-1.4249, 1.7330)
 (-5.4797, 0.0000) ( 1.8585,-1.5502) ( 4.4145,-0.7638) (-0.4805,-1.1976)
 ( 0.0000, 0.0000) ( 6.2673, 0.0000) (-0.4504,-0.0290) (-1.3467, 1.6579)
 ( 0.0000, 0.0000) ( 0.0000, 0.0000) (-3.5000, 0.0000) ( 2.5619,-3.3708)
                                                      :End of matrix H

出力結果

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

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

 Matrix H
                    1                 2                 3                 4
 1  (-3.9700,-5.0400) (-1.1318,-2.5693) (-4.6027,-0.1426) (-1.4249, 1.7330)
 2  (-5.4797, 0.0000) ( 1.8585,-1.5502) ( 4.4145,-0.7638) (-0.4805,-1.1976)
 3  ( 0.0000, 0.0000) ( 6.2673, 0.0000) (-0.4504,-0.0290) (-1.3467, 1.6579)
 4  ( 0.0000, 0.0000) ( 0.0000, 0.0000) (-3.5000, 0.0000) ( 2.5619,-3.3708)

 Eigenvalues
    (-6.0004,-6.9998) (-5.0000, 2.0060) ( 7.9982,-0.9964) ( 3.0023,-3.9998)

ソースコード

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

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


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

!     ZHSEQR Example Program Text

!     Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com

!     .. Use Statements ..
      Use blas_interfaces, Only: zgemm
      Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp
      Use lapack_interfaces, Only: zhseqr, zlange
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Complex (Kind=dp) :: alpha, beta
      Real (Kind=dp) :: norm
      Integer :: i, ifail, info, ldc, ldd, ldh, ldz, lwork, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: c(:, :), d(:, :), h(:, :), w(:), &
        work(:), z(:, :)
      Real (Kind=dp) :: rwork(1)
      Character (1) :: clabs(1), rlabs(1)
!     .. Intrinsic Procedures ..
      Intrinsic :: cmplx, epsilon
!     .. Executable Statements ..
      Write (nout, *) 'ZHSEQR Example Program Results'
      Write (nout, *)
      Flush (nout)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n
      ldc = n
      ldd = n
      ldh = n
      ldz = n
      lwork = n
      Allocate (c(ldc,n), d(ldd,n), h(ldh,n), w(n), work(lwork), z(ldz,n))

!     Read H from data file

      Read (nin, *)(h(i,1:n), i=1, n)

!     Store H in D
      d(1:ldd, 1:n) = h(1:ldh, 1:n)

!     Print matrix H
!     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, h, &
        ldh, 'Bracketed', 'F7.4', 'Matrix H', 'Integer', rlabs, 'Integer', &
        clabs, 80, 0, ifail)

!     Calculate the eigenvalues and Schur factorization of H

      Call zhseqr('Schur form', 'Initialize Z', n, 1, n, h, ldh, w, z, ldz, &
        work, lwork, info)

      Write (nout, *)
      If (info>0) Then
        Write (nout, *) 'Failure to converge.'
      Else

!       Compute A - Z*T*Z^H from Schur factorization of A, and store in matrix
!       D
        alpha = cmplx(1, kind=dp)
        beta = cmplx(0, kind=dp)
        Call zgemm('N', 'N', n, n, n, alpha, z, ldz, h, ldh, beta, c, ldc)
        alpha = cmplx(-1, kind=dp)
        beta = cmplx(1, kind=dp)
        Call zgemm('N', 'C', n, n, n, alpha, c, ldc, z, ldz, beta, d, ldd)

!       Find norm of matrix D and print warning if it is too large
        norm = zlange('O', ldd, n, d, ldd, rwork)

        If (norm>epsilon(1.0E0_dp)**0.5_dp) Then
          Write (nout, *) 'Norm of A-(Z*T*Z^H) is much greater than 0.'
          Write (nout, *) 'Schur factorization has failed.'
        Else
!         Print eigenvalues
          Write (nout, *) 'Eigenvalues'
          Write (nout, 100)(w(i), i=1, n)
        End If

      End If

100   Format ((3X,4(' (',F7.4,',',F7.4,')',:)))
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks