複素 QR 分解: 複素一般行列の列ピボット選択付き QR 分解

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

ホーム > LAPACKサンプルプログラム目次 > 複素 QR 分解 > 複素一般行列の列ピボット選択付き QR 分解

概要

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

入力データ

(本ルーチンの詳細はZGEQPF のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12

このデータをダウンロード
ZGEQPF Example Program Data
  5  4  2                                          :Values of M, N and NRHS
 ( 0.47,-0.34) (-0.40, 0.54) ( 0.60, 0.01) ( 0.80,-1.02)
 (-0.32,-0.23) (-0.05, 0.20) (-0.26,-0.44) (-0.43, 0.17)
 ( 0.35,-0.60) (-0.52,-0.34) ( 0.87,-0.11) (-0.34,-0.09)
 ( 0.89, 0.71) (-0.45,-0.45) (-0.02,-0.57) ( 1.14,-0.78)
 (-0.19, 0.06) ( 0.11,-0.85) ( 1.44, 0.80) ( 0.07, 1.14)   :End of matrix A
 (-0.85,-1.63) ( 2.49, 4.01)
 (-2.16, 3.52) (-0.14, 7.98)
 ( 4.57,-5.71) ( 8.36,-0.28)
 ( 6.38,-7.40) (-3.55, 1.29)
 ( 8.41, 9.39) (-6.72, 5.03)                               :End of matrix B

出力結果

(本ルーチンの詳細はZGEQPF のマニュアルページを参照)
1
2
3
4
5
6
7
8

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

 Least squares solution
                    1                 2
 1  ( 0.0000, 0.0000) ( 0.0000, 0.0000)
 2  ( 2.6925, 8.0446) (-2.0563,-2.9759)
 3  ( 2.7602, 2.5455) ( 1.0588, 1.4635)
 4  ( 2.7383, 0.5123) (-1.4150, 0.2982)

ソースコード

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

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

!     ZGEQPF Example Program Text

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

!     .. Use Statements ..
      Use blas_interfaces, Only: ztrsv
      Use lapack_example_aux, Only: nagf_file_print_matrix_complex_gen_comp
      Use lapack_interfaces, Only: zgeqp3, zunmqr
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Complex (Kind=dp), Parameter :: zero = (0.0E0_dp, 0.0E0_dp)
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=dp) :: tol
      Integer :: i, ifail, info, k, lda, ldb, ldx, lwork, m, n, nrhs
!     .. Local Arrays ..
      Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), tau(:), work(:), &
        x(:, :)
      Real (Kind=dp), Allocatable :: rwork(:)
      Integer, Allocatable :: jpvt(:)
      Character (1) :: clabs(1), rlabs(1)
!     .. Intrinsic Procedures ..
      Intrinsic :: abs
!     .. Executable Statements ..
      Write (nout, *) 'ZGEQPF Example Program Results'
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) m, n, nrhs
      lda = m
      ldb = m
      ldx = m
      lwork = 64*n
      Allocate (a(lda,n), b(ldb,nrhs), tau(n), work(lwork), x(ldx,nrhs), &
        rwork(2*n), jpvt(n))

!     Read A and B from data file

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

!     Initialize JPVT to be zero so that all columns are free

      jpvt(1:n) = 0

!     Compute the QR factorization of A
      Call zgeqp3(m, n, a, lda, jpvt, tau, work, lwork, rwork, info)

!     Choose TOL to reflect the relative accuracy of the input data

      tol = 0.01_dp

!     Determine which columns of R to use

loop: Do k = 1, n
        If (abs(a(k,k))<=tol*abs(a(1,1))) Then
          Exit loop
        End If
      End Do loop

!     Compute C = (Q**H)*B, storing the result in B

      k = k - 1

      Call zunmqr('Left', 'Conjugate Transpose', m, nrhs, k, a, lda, tau, b, &
        ldb, work, lwork, info)

!     Compute least squares solution by back-substitution in R*B = C

      Do i = 1, nrhs

        Call ztrsv('Upper', 'No transpose', 'Non-Unit', k, a, lda, b(1,i), 1)

!       Set the unused elements of the I-th solution vector to zero

        b(k+1:n, i) = zero

      End Do

!     Unscramble the least squares solution stored in B

      Do i = 1, n
        x(jpvt(i), 1:nrhs) = b(i, 1:nrhs)
      End Do

!     Print least squares solution

      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, nrhs, x, &
        ldx, 'Bracketed', 'F7.4', 'Least squares solution', 'Integer', rlabs, &
        'Integer', clabs, 80, 0, ifail)

    End Program


ご案内
関連情報
© 日本ニューメリカルアルゴリズムズグループ株式会社 2025
Privacy Policy  /  Trademarks