計算ルーチン: DGEHRD により決まるヘッセンベルグ形への縮約からの直交変換行列の適用

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

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > DGEHRD により決まるヘッセンベルグ形への縮約からの直交変換行列の適用

概要

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

入力データ

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

このデータをダウンロード
DORMHR Example Program Data
  4                           :Value of N
  0.35   0.45  -0.14  -0.17
  0.09   0.07  -0.54   0.35
 -0.44  -0.33  -0.03   0.17
  0.25  -0.32  -0.13   0.11   :End of matrix A
  0.0                         :Value of THRESH

出力結果

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

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

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

 Contents of array C
          1       2       3
 1  -0.1933  0.2546  0.1253
 2   0.2519 -0.5224  0.3320
 3   0.0972 -0.3084  0.5938
 4   0.6760  0.0000  0.7221

ソースコード

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

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


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

!     DORMHR Example Program Text

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

!     .. Use Statements ..
      Use blas_interfaces, Only: dnrm2
      Use lapack_example_aux, Only: nagf_blas_damax_val, &
        nagf_file_print_matrix_real_gen
      Use lapack_interfaces, Only: dgehrd, dhsein, dhseqr, dormhr
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Real (Kind=dp), Parameter :: zero = 0.0_dp
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Complex (Kind=dp) :: eig, eig1
      Real (Kind=dp) :: r, thresh
      Integer :: i, ifail, info, j, k, l, lda, ldc, ldh, ldvl, ldz, lwork, m, &
        n
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: a(:, :), c(:, :), h(:, :), tau(:), &
        vl(:, :), wi(:), work(:), wr(:), z(:, :)
      Integer, Allocatable :: ifaill(:), ifailr(:)
      Logical, Allocatable :: select(:)
!     .. Intrinsic Procedures ..
      Intrinsic :: aimag, cmplx, conjg, maxloc, real, sqrt, sum
!     .. Executable Statements ..
      Write (nout, *) 'DORMHR Example Program Results'
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n
      ldz = 1
      lda = n
      ldc = n
      ldh = n
      ldvl = n
      lwork = 64*n
      Allocate (a(lda,n), c(ldc,n), h(ldh,n), tau(n), vl(ldvl,n), wi(n), &
        work(lwork), wr(n), z(ldz,1), ifaill(n), ifailr(n), select(n))

!     Read A from data file

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

      Read (nin, *) thresh

!     Reduce A to upper Hessenberg form H = (Q**T)*A*Q
      Call dgehrd(n, 1, n, a, lda, tau, work, lwork, info)

!     Copy A to H
      h(1:n, 1:n) = a(1:n, 1:n)

!     Calculate the eigenvalues of H (same as A)
      Call dhseqr('Eigenvalues', 'No vectors', n, 1, n, h, ldh, wr, wi, z, &
        ldz, work, lwork, info)

      Write (nout, *)
      If (info>0) Then
        Write (nout, *) 'Failure to converge.'
      Else
        Write (nout, *) 'Eigenvalues'
        Write (nout, 100)(' (', wr(i), ',', wi(i), ')', i=1, n)

        Do i = 1, n
          select(i) = wr(i) < thresh
        End Do

!       Calculate the eigenvectors of H (as specified by SELECT),
!       storing the result in C
        Call dhsein('Right', 'QR', 'No initial vectors', select, n, a, lda, &
          wr, wi, vl, ldvl, c, ldc, n, m, work, ifaill, ifailr, info)

!       Calculate the eigenvectors of A = Q * (eigenvectors of H)
        Call dormhr('Left', 'No transpose', n, m, 1, n, a, lda, tau, c, ldc, &
          work, lwork, info)

!       Print eigenvectors

        Write (nout, *)
        Flush (nout)

!       Normalize selected eigenvectors
        j = 0
        k = 1
        Do While (k<=n)
          If (select(k)) Then
            j = j + 1
            If (wi(k)==0.0_dp) Then
!             Normalize real eigenvector by making largest positive
              Call nagf_blas_damax_val(n, c(1,j), 1, l, r)
              r = dnrm2(n, c(1,j), 1)
              c(1:n, j) = c(1:n, j)/r
              If (c(l,j)<zero) Then
                c(1:n, j) = -c(1:n, j)
              End If
            Else
!             Normalize complex eigenvectors making largest element real
              work(1:n) = c(1:n, j)**2 + c(1:n, j+1)**2
              l = maxloc(work(1:n), 1)
              eig1 = cmplx(c(l,j), c(l,j+1), kind=dp)
              eig1 = conjg(eig1)/sqrt(work(l)*sum(work(1:n)))
              Do i = 1, n
                eig = cmplx(c(i,j), c(i,j+1), kind=dp)
                eig = eig*eig1
                c(i, j) = real(eig)
                c(i, j+1) = aimag(eig)
              End Do
              c(l, j+1) = 0.0_dp
              j = j + 1
              k = k + 1
            End If
          End If
          k = k + 1
        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, m, c, ldc, &
          'Contents of array C', ifail)

      End If

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


ご案内
関連情報
Privacy Policy  /  Trademarks