実線形方程式: 三重対角行列 : (右辺はベクトル)

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

概要

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

以下の式を解きます。

\begin{displaymath}A x = b,\end{displaymath}

$ A$は三重対角行列です。

\begin{displaymath}A = \left(\begin{array}{rrrrr}3.0 & 2.1 & 0 & 0 & 0  ......2.7 \\-0.5 \\2.6 \\0.6 \\2.7\end{array} \right).\end{displaymath}

入力データ (本ルーチンの詳細はDGTSV のマニュアルページを参照)

1
2
3
4
5
6

このデータをダウンロード
DGTSV Example Program Data
  5                            :Value of N
        2.1  -1.0   1.9   8.0
  3.0   2.3  -5.0  -0.9   7.1
  3.4   3.6   7.0  -6.0        :End of matrix A
  2.7  -0.5   2.6   0.6   2.7  :End of vector B

出力結果

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

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

 Solution
     -4.0000     7.0000     3.0000    -4.0000    -3.0000

ソースコード

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

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

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

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

!     DGTSV Example Program Text

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

!     .. Use Statements ..
      Use lapack_interfaces, Only: dgtsv
      Use lapack_precision, Only: dp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer :: info, n
!     .. Local Arrays ..
      Real (Kind=dp), Allocatable :: b(:), d(:), dl(:), du(:)
!     .. Executable Statements ..
      Write (nout, *) 'DGTSV Example Program Results'
      Write (nout, *)
!     Skip heading in data file
      Read (nin, *)
      Read (nin, *) n

      Allocate (b(n), d(n), dl(n-1), du(n-1))

!     Read the tridiagonal matrix A and the right hand side B from
!     data file

      Read (nin, *) du(1:n-1)
      Read (nin, *) d(1:n)
      Read (nin, *) dl(1:n-1)
      Read (nin, *) b(1:n)

!     Solve the equations Ax = b for x

      Call dgtsv(n, 1, dl, d, du, b, n, info)

      If (info==0) Then

!       Print solution

        Write (nout, *) 'Solution'
        Write (nout, 100) b(1:n)

      Else
        Write (nout, 110) 'The (', info, ',', info, ')', &
          ' element of the factor U is zero'
      End If

100   Format ((1X,7F11.4))
110   Format (1X, A, I3, A, I3, A, A)
    End Program


ご案内
関連情報
© 譌・譛ャ繝九Η繝シ繝。繝ェ繧ォ繝ォ繧「繝ォ繧エ繝ェ繧コ繝�繧コ繧ー繝ォ繝シ繝玲�ェ蠑丈シ夂、セ 2025
Privacy Policy  /  Trademarks