実線形方程式: 一般行列 : (右辺は行列)

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

概要

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

以下の式を解きます。

\begin{displaymath}
A X = B,
\end{displaymath}

$ A$は一般行列です。

\begin{displaymath}
A = \left(
\begin{array}{rrrr}
1.80 & 2.88 & 2.05 & -0.89...
...00 \\
0.77 & -13.28 \\
-6.22 & -6.21
\end{array} \right).
\end{displaymath}

解のエラー推定値、スケーリングについての情報、スケーリングされた行列$ A$の条件数の逆数の推定値、$ A$の分解においての軸要素成長乗数の逆数の推定値も合わせて出力されます。

入力データ

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

このデータをダウンロード
DGESVX Example Program Data

    4        2                     :Values of N and NRHS

    1.80     2.88    2.05    -0.89
  525.00  -295.00  -95.00  -380.00
    1.58    -2.69   -2.90    -1.04
   -1.11    -0.66   -0.59     0.80 :End of matrix A

    9.52    18.47
 2435.00   225.00
    0.77   -13.28
   -6.22    -6.21                  :End of matrix B

出力結果

(本ルーチンの詳細はDGESVX のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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

 Solution(s)
             1          2
 1      1.0000     3.0000
 2     -1.0000     2.0000
 3      3.0000     4.0000
 4     -5.0000     1.0000

 Backward errors (machine-dependent)
       6.8E-17    9.1E-17

 Estimated forward error bounds (machine-dependent)
       2.4E-14    3.6E-14

 A has been row scaled as diag(R)*A

 Reciprocal condition number estimate of scaled matrix
       1.8E-02

 Estimate of reciprocal pivot growth factor
       7.4E-01

ソースコード

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

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

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

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

!     DGESVX 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: dgesvx
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=dp) :: rcond
      Integer :: i, ifail, info, lda, ldaf, ldb, ldx, n, nrhs
      Character (1) :: equed
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: a(:, :), af(:, :), b(:, :), berr(:), &
        c(:), ferr(:), r(:), work(:), x(:, :)
      Integer, Allocatable :: ipiv(:), iwork(:)
!     .. Executable Statements ..
      Write (nout, *) 'DGESVX Example Program Results'
      Write (nout, *)
      Flush (nout)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n, nrhs
      lda = n
      ldaf = n
      ldb = n
      ldx = n
      Allocate (a(lda,n), af(ldaf,n), b(ldb,nrhs), berr(nrhs), c(n), &
        ferr(nrhs), r(n), work(4*n), x(ldx,nrhs), ipiv(n), iwork(n))

!     Read A and B from data file

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

!     Solve the equations AX = B for X

      Call dgesvx('Equilibration', 'No transpose', n, nrhs, a, lda, af, ldaf, &
        ipiv, equed, r, c, b, ldb, x, ldx, rcond, ferr, berr, work, iwork, &
        info)

      If ((info==0) .Or. (info==n+1)) Then

!       Print solution, error bounds, condition number, the form
!       of equilibration and the pivot growth factor

!       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, nrhs, x, ldx, &
          'Solution(s)', ifail)

        Write (nout, *)
        Write (nout, *) 'Backward errors (machine-dependent)'
        Write (nout, 100) berr(1:nrhs)
        Write (nout, *)
        Write (nout, *) 'Estimated forward error bounds (machine-dependent)'
        Write (nout, 100) ferr(1:nrhs)
        Write (nout, *)
        If (equed=='N') Then
          Write (nout, *) 'A has not been equilibrated'
        Else If (equed=='R') Then
          Write (nout, *) 'A has been row scaled as diag(R)*A'
        Else If (equed=='C') Then
          Write (nout, *) 'A has been column scaled as A*diag(C)'
        Else If (equed=='B') Then
          Write (nout, *) &
            'A has been row and column scaled as diag(R)*A*diag(C)'
        End If
        Write (nout, *)
        Write (nout, *) &
          'Reciprocal condition number estimate of scaled matrix'
        Write (nout, 100) rcond
        Write (nout, *)
        Write (nout, *) 'Estimate of reciprocal pivot growth factor'
        Write (nout, 100) work(1)

        If (info==n+1) Then
          Write (nout, *)
          Write (nout, *) 'The matrix A is singular to working precision'
        End If
      Else
        Write (nout, 110) 'The (', info, ',', info, ')', &
          ' element of the factor U is zero'
      End If

100   Format ((3X,1P,7E11.1))
110   Format (1X, A, I3, A, I3, A, A)
    End Program


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