計算ルーチン: DGEBRD により決まる準対角形への縮約からの直交変換行列の生成

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

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

概要

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

入力データ

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

このデータをダウンロード
DORGBR Example Program Data
  6  4                                      :Values of M and N, Example 1
 -0.57  -1.28  -0.39   0.25
 -1.93   1.08  -0.31  -2.14
  2.30   0.24   0.40  -0.35
 -1.93   0.64  -0.66   0.08
  0.15   0.30   0.15  -2.13
 -0.02   1.03  -1.43   0.50                 :End of matrix A
  4  6                                      :Values of M and N, Example 2
 -5.42   3.28  -3.68   0.27   2.06   0.46
 -1.65  -3.40  -3.20  -1.03  -4.06  -0.01
 -0.37   2.35   1.90   4.31  -1.76   1.13
 -3.15  -0.11   1.99  -2.70   0.26   4.50   :End of matrix A

出力結果

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

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

 Example 1: singular values
     3.9987  3.0005  1.9967  0.9999

 Example 1: right singular vectors, by row
          1       2       3       4
 1   0.8251 -0.2794  0.2048  0.4463
 2  -0.4530 -0.2121 -0.2622  0.8252
 3  -0.2829 -0.7961  0.4952 -0.2026
 4   0.1841 -0.4931 -0.8026 -0.2807

 Example 1: left singular vectors, by column
          1       2       3       4
 1  -0.0203  0.2794  0.4690  0.7692
 2  -0.7284 -0.3464 -0.0169 -0.0383
 3   0.4393 -0.4955 -0.2868  0.0822
 4  -0.4678  0.3258 -0.1536 -0.1636
 5  -0.2200 -0.6428  0.1125  0.3572
 6  -0.0935  0.1927 -0.8132  0.4957

 Example 2: singular values
     7.9987  7.0059  5.9952  4.9989

 Example 2: right singular vectors, by row
          1       2       3       4       5       6
 1  -0.7933  0.3163 -0.3342 -0.1514  0.2142  0.3001
 2   0.1002  0.6442  0.4371  0.4890  0.3771  0.0501
 3   0.0111  0.1724 -0.6367  0.4354 -0.0430 -0.6111
 4   0.2361  0.0216 -0.1025 -0.5286  0.7460 -0.3120

 Example 2: left singular vectors, by column
          1       2       3       4
 1   0.8884  0.1275  0.4331  0.0838
 2   0.0733 -0.8264  0.1943 -0.5234
 3  -0.0361  0.5435  0.0756 -0.8352
 4   0.4518 -0.0733 -0.8769 -0.1466

ソースコード

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

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


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

!     DORGBR Example Program Text

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

!     .. Use Statements ..
      Use lapack_example_aux, Only: nagf_file_print_matrix_real_gen
      Use lapack_interfaces, Only: dbdsqr, dgebrd, dlacpy, dorgbr
      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 ..
      Real (Kind=dp), Allocatable :: a(:, :), c(:, :), d(:), e(:), taup(:), &
        tauq(:), u(:, :), vt(:, :), work(:)
!     .. Executable Statements ..
      Write (nout, *) 'DORGBR 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), d(n), e(n-1), taup(n), tauq(n), &
          u(ldu,n), vt(ldvt,n), work(lwork))

!       Read A from data file

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

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

        If (m>=n) Then

!         Copy A to VT and U

          Call dlacpy('Upper', n, n, a, lda, vt, ldvt)
          Call dlacpy('Lower', m, n, a, lda, u, ldu)

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

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

!         Compute the SVD of A
          Call dbdsqr('Upper', n, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &
            work, 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_real_gen('General', ' ', n, n, vt, ldvt, &
            'Example 1: right singular vectors, by row', ifail)

          Write (nout, *)
          Flush (nout)

          Call nagf_file_print_matrix_real_gen('General', ' ', m, n, u, ldu, &
            'Example 1: left singular vectors, by column', ifail)

        Else

!         Copy A to VT and U

          Call dlacpy('Upper', m, n, a, lda, vt, ldvt)
          Call dlacpy('Lower', m, m, a, lda, u, ldu)

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

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

!         Compute the SVD of A
          Call dbdsqr('Lower', m, n, m, 0, d, e, vt, ldvt, u, ldu, c, ldc, &
            work, 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_real_gen('General', ' ', m, n, vt, ldvt, &
            'Example 2: right singular vectors, by row', ifail)

          Write (nout, *)
          Flush (nout)

          Call nagf_file_print_matrix_real_gen('General', ' ', m, m, u, ldu, &
            'Example 2: left singular vectors, by column', ifail)

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

100   Format (3X, (8F8.4))
    End Program


ご案内
関連情報
Privacy Policy  /  Trademarks