Keyword: 実行列, LU分解
概要
本サンプルは実行列のLU分解を行うFortranによるサンプルプログラムです。 本サンプルは以下に示される行列AのLU分解を行いその結果を出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン f07adf() のExampleコードです。本サンプル及びルーチンの詳細情報は f07adf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はf07adf のマニュアルページを参照)| このデータをダウンロード |
F07ADF Example Program Data 4 4 :Values of M and N 1.80 2.88 2.05 -0.89 5.25 -2.95 -0.95 -3.80 1.58 -2.69 -2.90 -1.04 -1.11 -0.66 -0.59 0.80 :End of matrix A
- 1行目はタイトル行で読み飛ばされます。
- 2行目に行列Aの行数(m)と列数(n)を指定しています。
- 3〜6行目に行列Aの要素を指定しています。
出力結果
(本ルーチンの詳細はf07adf のマニュアルページを参照)| この出力例をダウンロード |
F07ADF Example Program Results
Details of factorization
1 2 3 4
1 5.2500 -2.9500 -0.9500 -3.8000
2 0.3429 3.8914 2.3757 0.4129
3 0.3010 -0.4631 -1.5139 0.2948
4 -0.2114 -0.3299 0.0047 0.1314
IPIV
2 2 3 4
- 5〜8行目にLU分解の結果が出力されています。
- 11行目にピボット指数が出力されています。
ソースコード
(本ルーチンの詳細はf07adf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM f07adfe
! F07ADF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : dgetrf, nag_wp, x04caf
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: nin = 5, nout = 6
! .. Local Scalars ..
INTEGER :: i, ifail, info, lda, m, n
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:)
INTEGER, ALLOCATABLE :: ipiv(:)
! .. Intrinsic Functions ..
INTRINSIC min
! .. Executable Statements ..
WRITE (nout,*) 'F07ADF Example Program Results'
! Skip heading in data file
READ (nin,*)
READ (nin,*) m, n
lda = m
ALLOCATE (a(lda,n),ipiv(n))
! Read A from data file
READ (nin,*) (a(i,1:n),i=1,m)
! Factorize A
! The nAG name equivalent of dgetrf is f07adf
CALL dgetrf(m,n,a,lda,ipiv,info)
! Print details of factorization
WRITE (nout,*)
FLUSH (nout)
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
CALL x04caf('General',' ',m,n,a,lda,'Details of factorization',ifail)
! Print pivot indices
WRITE (nout,*)
WRITE (nout,*) 'IPIV'
WRITE (nout,99999) ipiv(1:min(m,n))
IF (info/=0) WRITE (nout,*) 'The factor U is singular'
99999 FORMAT ((3X,7I11))
END PROGRAM f07adfe
