計算ルーチン: 複素行列の特異値分解 : (オプションで左および/または右特異ベクトル(前処理付きヤコビ))

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

概要

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

入力データ

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

このデータをダウンロード
ZGEJSV Example Program Data
  6  4                                                   : m and n
 ( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06) (-0.05, 0.41)
 (-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42) (-0.81, 0.56)
 ( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17) (-1.11, 0.60)
 (-0.37, 0.38) ( 0.19,-0.54) (-0.98,-0.36) ( 0.22,-0.20)
 ( 0.83, 0.51) ( 0.20, 0.01) (-0.17,-0.46) ( 1.47, 1.59)
 ( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23) ( 0.26, 0.26) : matrix A

出力結果

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

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

 Singular values
     3.9994  3.0003  1.9944  0.9995

 Left singular vectors
          1       2       3       4
 1   0.5634 -0.1804  0.0757  0.0127
    -0.0021  0.3395 -0.5208  0.4822
 
 2  -0.1200  0.1917 -0.4535  0.0220
     0.6109  0.2443 -0.1124 -0.0420
 
 3   0.0815  0.4205  0.6021  0.1237
    -0.1614  0.0403 -0.0346 -0.2071
 
 4  -0.1440 -0.2257  0.0942  0.5805
     0.1534 -0.1364 -0.1237 -0.1439
 
 5   0.2488  0.1251 -0.2252  0.0533
     0.0924 -0.6961 -0.1398  0.0860
 
 6   0.3758 -0.0684  0.0004  0.0448
    -0.0796  0.0540 -0.2158 -0.5805

Warning: Floating underflow occurred
 Right singular vectors
          1       2       3       4
 1   0.6971 -0.0729  0.4144 -0.2817
    -0.0006 -0.2289  0.3013 -0.3384
 
 2   0.0864  0.2006  0.3471  0.8276
    -0.3549 -0.1400  0.0379 -0.0000
 
 3  -0.0564  0.5794 -0.3585 -0.2202
    -0.5399  0.0755  0.3776 -0.2106
 
 4   0.1876 -0.4206 -0.5845  0.1264
    -0.2254 -0.6035  0.0527  0.1116


 Estimate of the condition number of column equilibrated A
       2.61E+00

 Error estimates (as multiples of machine precision):

   for the singular values
       4

   for left singular vectors
       4   4   4   4

   for right singular vectors
       4   4   4   4

ソースコード

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

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


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

!     ZGEJSV Example Program Text

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

!     .. Use Statements ..
      Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen
      Use lapack_interfaces, Only: ddisna, zgejsv
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=dp) :: eps, serrbd
      Integer :: i, ifail, info, j, lda, ldu, ldv, lrwork, lwork, m, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: a(:, :), cwork(:), u(:, :), v(:, :)
      Real (Kind=dp), Allocatable :: rcondu(:), rcondv(:), rwork(:), sva(:)
      Integer, Allocatable :: iwork(:)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs, epsilon, nint
!     .. Executable Statements ..
      Write (nout, *) 'ZGEJSV Example Program Results'
      Write (nout, *)
      Flush (nout)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) m, n
      lda = m
      ldu = m
      ldv = n
      lwork = 5*n + n*n + 1000
      lrwork = n + 2*m + 7
      Allocate (a(lda,n), rcondu(m), rcondv(m), sva(n), u(ldu,n), v(ldv,n), &
        cwork(lwork), rwork(lrwork), iwork(m+3*n+3))

!     Read the m by n matrix A from data file
      Read (nin, *)((a(i,j),j=1,n), i=1, m)

!     Compute the singular values and left and right singular vectors
!     of A (A = U*S*V^T, m.ge.n)
      Call zgejsv('E', 'U', 'V', 'R', 'N', 'N', m, n, a, lda, sva, u, ldu, v, &
        ldv, cwork, lwork, rwork, lrwork, iwork, info)

      If (info==0) Then

!       Compute the approximate error bound for the computed singular values
!       using the 2-norm, s(1) = norm(A), and machine precision, eps.
        eps = epsilon(1.0E0_dp)
        serrbd = eps*sva(1)

!       Print solution
        If (abs(rwork(1)-rwork(2))<2.0_dp*eps) Then
!         No scaling required
          Write (nout, '(1X,A)') 'Singular values'
          Write (nout, 100)(sva(j), j=1, n)
        Else
          Write (nout, '(/1X,A)') 'Scaled singular values'
          Write (nout, 100)(sva(j), j=1, n)
          Write (nout, '(/1X,A)') 'For true singular values, multiply by a/b,'
          Write (nout, 140) ' where a = ', rwork(1), ' and b = ', rwork(2)
        End If

!       ifail: behaviour on error exit
!              =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
        Write (nout, *)
        Flush (nout)
        ifail = 0
        Call nagf_file_print_matrix_complex_gen('General', ' ', m, n, u, ldu, &
          'Left singular vectors', ifail)

        Write (nout, *)
        Flush (nout)
        ifail = 0
        Call nagf_file_print_matrix_complex_gen('General', ' ', n, n, v, ldv, &
          'Right singular vectors', ifail)

!       Call DDISNA to estimate reciprocal condition numbers for
!       the singular vectors.

        Call ddisna('Left', m, n, sva, rcondu, info)
        Call ddisna('Right', m, n, sva, rcondv, info)

!       Print the approximate error bounds for the singular values
!       and vectors.
        Write (nout, *)
        Write (nout, '(/1X,A)') &
          'Estimate of the condition number of column equilibrated A'
        Write (nout, 110) rwork(3)
        Write (nout, '(/1X,A)') &
          'Error estimates (as multiples of machine precision):'
        Write (nout, '(/1X,A)') '  for the singular values'
        Write (nout, 120) nint(serrbd/epsilon(1.0E0_dp))
        Write (nout, '(/1X,A)') '  for left singular vectors'
        Write (nout, 120)(nint(serrbd/rcondu(i)/epsilon(1.0E0_dp)), i=1, n)
        Write (nout, '(/1X,A)') '  for right singular vectors'
        Write (nout, 120)(nint(serrbd/rcondv(i)/epsilon(1.0E0_dp)), i=1, n)
      Else
        Write (nout, 130) 'Failure in ZGEJSV. INFO =', info
      End If

100   Format (3X, 8F8.4)
110   Format (4X, 1P, E11.2)
120   Format (4X, 6I4)
130   Format (1X, A, I4)
140   Format (1X, 2(A,1P,E13.5))
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks