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

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

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

概要

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

入力データ

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

このデータをダウンロード
DHSEQR Example Program Data
  4                                   :Value of N
  0.3500  -0.1160  -0.3886  -0.2942
 -0.5140   0.1225   0.1004   0.1126
  0.0000   0.6443  -0.1357  -0.0977
  0.0000   0.0000   0.4262   0.1632   :End of matrix H

出力結果

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

この出力例をダウンロード
 DHSEQR Example Program Results
 Matrix H
          1       2       3       4
 1   0.3500 -0.1160 -0.3886 -0.2942
 2  -0.5140  0.1225  0.1004  0.1126
 3   0.0000  0.6443 -0.1357 -0.0977
 4   0.0000  0.0000  0.4262  0.1632

 Eigenvalues
  (  0.7995,  0.0000)
  ( -0.0994,  0.4008)
  ( -0.0994, -0.4008)
  ( -0.1007,  0.0000)

ソースコード

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

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


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

!     DHSEQR Example Program Text

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

!     .. Use Statements ..
      Use blas_interfaces, Only: dgemm
      Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen
      Use lapack_interfaces, Only: dhseqr, dlange
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=dp) :: alpha, beta, norm
      Integer :: i, ifail, info, ldc, ldd, ldh, ldz, lwork, n
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: c(:, :), d(:, :), h(:, :), wi(:), &
        work(:), wr(:), z(:, :)
!     .. Intrinsic Procedures ..
      Intrinsic :: epsilon
!     .. Executable Statements ..
      Write (nout, *) 'DHSEQR Example Program Results'
      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), wi(n), work(lwork), wr(n), &
        z(ldz,n))

!     Read H from data file
      Read (nin, *)(h(i,1:n), i=1, n)

!     Copy H into D
      d(1:n, 1:n) = h(1:n, 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_real_gen('General', ' ', n, n, h, ldh, &
        'Matrix H', ifail)

!     Calculate the eigenvalues and Schur factorization of H

      Call dhseqr('Schur form', 'Initialize Z', n, 1, n, h, ldh, wr, wi, z, &
        ldz, work, lwork, info)

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

!       Compute H - Z*T*Z^T from the factorization of A and store in matrix D
        alpha = 1.0_dp
        beta = 0.0_dp
        Call dgemm('N', 'N', n, n, n, alpha, z, ldz, h, ldh, beta, c, ldc)
        alpha = -1.0_dp
        beta = 1.0_dp
        Call dgemm('N', 'T', 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 = dlange('O', ldd, n, d, ldd, work)
        If (norm>epsilon(1.0E0_dp)**0.8_dp) Then
          Write (nout, *) 'Norm of H-(Z*T*Z^T) is much greater than 0.'
          Write (nout, *) 'Schur factorization has failed.'
        Else
!         Print eigenvalues
          Write (nout, *) 'Eigenvalues'
          Write (nout, 100)(' (', wr(i), ',', wi(i), ')', i=1, n)
        End If
      End If

100   Format (1X, A, F8.4, A, F8.4, A)
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks