計算ルーチン: ZGEBRD により決まる準対角形への縮約からユニタリ変換行列の生成

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

ホーム > LAPACKサンプルプログラム目次 > 計算ルーチン > ZGEBRD により決まる準対角形への縮約からユニタリ変換行列の生成

概要

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

入力データ

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

このデータをダウンロード
ZUNGBR Example Program Data
  6  4                                        :Values of M and N, Example 1
 ( 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)   :End of matrix A
  3  4                                        :Values of M and N, Example 2
 ( 0.28,-0.36) ( 0.50,-0.86) (-0.77,-0.48) ( 1.58, 0.66)
 (-0.50,-1.10) (-1.21, 0.76) (-0.32,-0.24) (-0.27,-1.15)
 ( 0.36,-0.51) (-0.07, 1.33) (-0.75, 0.47) (-0.08, 1.01)   :End of matrix A

出力結果

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

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

 Example 1: singular values
         3.9994            3.0003            1.9944            0.9995

 Example 1: right singular vectors, by row
                    1                 2                 3                 4
 1  (-0.6971,-0.0000) (-0.0867,-0.3548) ( 0.0560,-0.5400) (-0.1878,-0.2253)
 2  ( 0.2403, 0.0000) ( 0.0725,-0.2336) (-0.2477,-0.5291) ( 0.7026, 0.2177)
 3  (-0.5123, 0.0000) (-0.3030,-0.1735) ( 0.0678, 0.5162) ( 0.4418, 0.3864)
 4  (-0.4403, 0.0000) ( 0.5294, 0.6361) (-0.3027,-0.0346) ( 0.1667, 0.0258)

 Example 1: left singular vectors, by column
                    1                 2                 3                 4
 1  (-0.5634, 0.0016) (-0.2687,-0.2749) ( 0.2451, 0.4657) ( 0.3787, 0.2987)
 2  ( 0.1205,-0.6108) (-0.2909, 0.1085) ( 0.4329,-0.1758) (-0.0182,-0.0437)
 3  (-0.0816, 0.1613) (-0.1660, 0.3885) (-0.4667, 0.3821) (-0.0800,-0.2276)
 4  ( 0.1441,-0.1532) ( 0.1984,-0.1737) (-0.0034, 0.1555) ( 0.2608,-0.5382)
 5  (-0.2487,-0.0926) ( 0.6253, 0.3304) ( 0.2643,-0.0194) ( 0.1002, 0.0140)
 6  (-0.3758, 0.0793) (-0.0307,-0.0816) ( 0.1266, 0.1747) (-0.4175,-0.4058)

 Example 2: singular values
         3.0004            1.9967            0.9973

 Example 2: right singular vectors, by row
                    1                 2                 3                 4
 1  ( 0.2454,-0.0001) ( 0.2942,-0.5843) ( 0.0162,-0.0810) ( 0.6794, 0.2083)
 2  (-0.1692, 0.5194) ( 0.1915,-0.4374) ( 0.5205,-0.0244) (-0.3149,-0.3208)
 3  (-0.5553, 0.1403) ( 0.1438,-0.1507) (-0.5684,-0.5505) (-0.0318,-0.0378)

 Example 2: left singular vectors, by column
                    1                 2                 3
 1  ( 0.6518, 0.0000) (-0.4312, 0.0000) ( 0.6239, 0.0000)
 2  (-0.4437,-0.5027) (-0.3794, 0.1026) ( 0.2014, 0.5961)
 3  (-0.2012, 0.2916) (-0.8122, 0.0030) (-0.3511,-0.3026)

ソースコード

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

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


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

!     ZUNGBR 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_comp
      Use lapack_interfaces, Only: zbdsqr, zgebrd, zlacpy, zungbr
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer :: i, ic, ifail, info, lda, ldc, ldu, ldvt, lwork, m, n
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: a(:, :), c(:, :), taup(:), tauq(:), &
        u(:, :), vt(:, :), work(:)
      Real (Kind=dp), Allocatable :: d(:), e(:), rwork(:)
      Character (1) :: clabs(1), rlabs(1)
!     .. Executable Statements ..
      Write (nout, *) 'ZUNGBR Example Program Results'
!     Skip heading in data file
      Read (nin, *)
      Do ic = 1, 2
        Read (nin, *) m, n
        lda = m
        ldc = n
        ldu = m
        ldvt = n
        lwork = 64*(m+n)
        Allocate (a(lda,n), c(ldc,n), taup(n), tauq(n), u(ldu,n), vt(ldvt,n), &
          work(lwork), d(n), e(n-1), rwork(4*n-4))

!       Read A from data file
        Read (nin, *)(a(i,1:n), i=1, m)

!       Reduce A to bidiagonal form
        Call zgebrd(m, n, a, lda, d, e, tauq, taup, work, lwork, info)

        If (m>=n) Then

!         Copy A to VT and U
          Call zlacpy('Upper', n, n, a, lda, vt, ldvt)
          Call zlacpy('Lower', m, n, a, lda, u, ldu)

!         Form P**H explicitly, storing the result in VT
          Call zungbr('P', n, n, m, vt, ldvt, taup, work, lwork, info)

!         Form Q explicitly, storing the result in U
          Call zungbr('Q', m, n, n, u, ldu, tauq, work, lwork, info)

!         Compute the SVD of A
          Call zbdsqr('Upper', n, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &
            rwork, info)

!         Print singular values, left & right singular vectors

          Write (nout, *)
          Write (nout, *) 'Example 1: singular values'
          Write (nout, 100) d(1:n)
          Write (nout, *)
          Flush (nout)

!         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, &
            vt, ldvt, 'Bracketed', 'F7.4', &
            'Example 1: right singular vectors, by row', 'Integer', rlabs, &
            'Integer', clabs, 80, 0, ifail)

          Write (nout, *)
          Flush (nout)

          Call nagf_file_print_matrix_complex_gen_comp('General', ' ', m, n, &
            u, ldu, 'Bracketed', 'F7.4', &
            'Example 1: left singular vectors, by column', 'Integer', rlabs, &
            'Integer', clabs, 80, 0, ifail)

        Else

!         Copy A to VT and U
          Call zlacpy('Upper', m, n, a, lda, vt, ldvt)
          Call zlacpy('Lower', m, m, a, lda, u, ldu)

!         Form P**H explicitly, storing the result in VT
          Call zungbr('P', m, n, m, vt, ldvt, taup, work, lwork, info)

!         Form Q explicitly, storing the result in U
          Call zungbr('Q', m, m, n, u, ldu, tauq, work, lwork, info)

!         Compute the SVD of A
          Call zbdsqr('Lower', m, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &
            rwork, info)

!         Print singular values, left & right singular vectors

          Write (nout, *)
          Write (nout, *) 'Example 2: singular values'
          Write (nout, 100) d(1:m)
          Write (nout, *)
          Flush (nout)

          ifail = 0
          Call nagf_file_print_matrix_complex_gen_comp('General', ' ', m, n, &
            vt, ldvt, 'Bracketed', 'F7.4', &
            'Example 2: right singular vectors, by row', 'Integer', rlabs, &
            'Integer', clabs, 80, 0, ifail)

          Write (nout, *)
          Flush (nout)

          Call nagf_file_print_matrix_complex_gen_comp('General', ' ', m, m, &
            u, ldu, 'Bracketed', 'F7.4', &
            'Example 2: left singular vectors, by column', 'Integer', rlabs, &
            'Integer', clabs, 80, 0, ifail)

        End If
        Deallocate (a, c, taup, tauq, u, vt, work, d, e, rwork)
      End Do

100   Format (8X, 4(F7.4,11X,:))
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks