計算ルーチン: 実行列のシュール分解の並べ替え : (選択した固有値に対する右不変部分空間の正規直交規定を作る)

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

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > 実行列のシュール分解の並べ替え

概要

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

入力データ

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

このデータをダウンロード
DTRSEN Example Program Data
  4                                   :Value of N
  0.7995  -0.1144   0.0060   0.0336
  0.0000  -0.0994   0.2478   0.3474
  0.0000  -0.6483  -0.0994   0.2026
  0.0000   0.0000   0.0000  -0.1007   :End of matrix T
  0.6551   0.1037   0.3450   0.6641
  0.5236  -0.5807  -0.6141  -0.1068
 -0.5362  -0.3073  -0.2935   0.7293
  0.0956   0.7467  -0.6463   0.1249   :End of matrix Q
  T   F   F   T                       :End of SELECT

出力結果

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

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

 Matrix A computed from Q*T*Q^T
          1       2       3       4
 1   0.3500  0.4500 -0.1400 -0.1700
 2   0.0900  0.0700 -0.5399  0.3500
 3  -0.4400 -0.3300 -0.0300  0.1700
 4   0.2500 -0.3200 -0.1300  0.1100

 Condition number estimate of the selected cluster of eigenvalues =   1.75E+00

 Condition number estimate of the specified invariant subspace    =   3.22E+00

ソースコード

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

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


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

!     DTRSEN 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: dlange, dtrsen
      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, s, sep
      Integer :: i, ifail, info, lda, ldc, ldq, ldt, liwork, lwork, m, n
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: a(:, :), c(:, :), q(:, :), t(:, :), &
        wi(:), work(:), wr(:)
      Integer, Allocatable :: iwork(:)
      Logical, Allocatable :: select(:)
!     .. Intrinsic Procedures ..
      Intrinsic :: epsilon
!     .. Executable Statements ..
      Write (nout, *) 'DTRSEN Example Program Results'
      Write (nout, *)
      Flush (nout)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n
      lda = n
      ldc = n
      ldq = n
      ldt = n
      liwork = (n*n)/4
      lwork = (n*n)/2
      Allocate (a(lda,n), c(ldc,n), q(ldq,n), t(ldt,n), wi(n), work(lwork), &
        wr(n), iwork(liwork), select(n))

!     Read T, Q and the logical array SELECT from data file

      Read (nin, *)(t(i,1:n), i=1, n)
      Read (nin, *)(q(i,1:n), i=1, n)

      Read (nin, *) select(1:n)

!     Compute Q * T * Q**T to find  A
      alpha = 1._dp
      beta = 0._dp
      Call dgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)
      Call dgemm('N', 'T', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)

!     Print Matrix A, as computed from Q * T * Q**T
!     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, a, lda, &
        'Matrix A computed from Q*T*Q^T', ifail)

      Write (nout, *)
      Flush (nout)

!     Reorder the Schur factor T and update the matrix Q to obtain TT and QT

      Call dtrsen('Both', 'Vectors', select, n, t, ldt, q, ldq, wr, wi, m, s, &
        sep, work, lwork, iwork, liwork, info)

!     Compute (Q * T * Q^T) - (QT * TT * QT^T) and store in A,
!     i.e. the difference between reconstructed A using Schur and reordered
!          Schur decompositions.
      alpha = 1._dp
      beta = 0._dp
      Call dgemm('N', 'N', n, n, n, alpha, q, ldq, t, ldt, beta, c, ldc)
      alpha = -1._dp
      beta = 1._dp
      Call dgemm('N', 'T', n, n, n, alpha, c, ldc, q, ldq, beta, a, lda)

!     Find norm of difference matrix and print warning if it is too large
      norm = dlange('O', lda, n, a, lda, work)
      If (norm>epsilon(1.0E0_dp)**0.8_dp) Then
        Write (nout, *) 'Norm of A - (QT * TT * QT^T) is much greater than 0.'
        Write (nout, *) 'Schur factorization has failed.'
      Else
!       Print Result
        Write (nout, 100) 'Condition number estimate', &
          ' of the selected cluster of eigenvalues = ', 1.0_dp/s
        Write (nout, *)
        Write (nout, 100) 'Condition number estimate of the spec', &
          'ified invariant subspace    = ', 1.0_dp/sep
      End If

100   Format (1X, A, A, 1P, E10.2)
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks