Keyword: 疑似逆行列, ランク, 階数, 逆行列
概要
本サンプルは実行列の疑似逆行列とランクを求めるFortranによるサンプルプログラムです。 本サンプルは以下に示される行列Aの疑似逆行列とランクを求めその結果を出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン f01blf() のExampleコードです。本サンプル及びルーチンの詳細情報は f01blf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はf01blf のマニュアルページを参照)| このデータをダウンロード |
F01BLF Example Program Data 6 5 : m, n 7.0 -2.0 4.0 9.0 1.8 3.0 8.0 -4.0 6.0 1.3 9.0 6.0 1.0 5.0 2.1 -8.0 7.0 5.0 2.0 0.6 4.0 -1.0 2.0 8.0 1.3 1.0 6.0 3.0 -5.0 0.5 : a
- 1行目はタイトル行で読み飛ばされます。
- 2行目に行列Aの行数mと列数nを指定しています。
- 3〜8行目に6x5の行列Aの要素を指定しています。最後の列は他の4つの列の線形結合となっています。
出力結果
(本ルーチンの詳細はf01blf のマニュアルページを参照)| この出力例をダウンロード |
F01BLF Example Program Results
Maximum element in A(K) for I.GE.K and J.GE.K
K Modulus
1 9.0000E+00
2 9.3101E+00
3 8.7461E+00
4 5.6832E+00
5 2.8449E-16
Rank = 4
T = 2.9948E-15 (machine dependent)
Transpose of pseudo-inverse
1.7807E-02 -2.1565E-02 5.2029E-02 2.3686E-02 7.1957E-03
-1.1826E-02 4.3417E-02 -8.1265E-02 3.5717E-02 -1.3957E-03
4.7157E-02 2.9446E-02 1.3926E-02 -1.3808E-02 7.6720E-03
-5.6636E-02 2.9132E-02 4.7442E-02 3.0478E-02 5.0415E-03
-3.6741E-03 -1.3781E-02 1.6647E-02 3.5665E-02 3.4857E-03
3.8408E-02 3.4256E-02 5.7594E-02 -5.7134E-02 7.3123E-03
- 5〜10行目に行列因数分解の各ステップで残った要素の絶対値の最大値が出力されています。
- 12行目に行列Aのランクが出力されています。
- 14行目に要素をゼロとみなすかどうか決める際に使用される許容値(マシンイプシロン*行列Aのノルム)が出力されています。
- 17〜22行目に疑似逆行列の転置行列が出力されています。
ソースコード
(本ルーチンの詳細はf01blf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
Program f01blfe
! F01BLF Example Program Text
! Mark 24 Release. nAG Copyright 2012.
! .. Use Statements ..
Use nag_library, Only: f01blf, f06raf, nag_wp, x02ajf, x04cbf
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: indent = 0, ncols = 80, nin = 5, &
nout = 6
Character (1), Parameter :: diag = 'N', matrix = 'G', nolabel = &
'N'
Character (8), Parameter :: form = '1P,E12.4'
! .. Local Scalars ..
Real (Kind=nag_wp) :: anorm, t
Integer :: i, ifail, irank, lda, ldu, m, n
Character (9) :: norm
Character (27) :: title
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: a(:,:), aijmax(:), d(:), du(:), u(:,:)
Real (Kind=nag_wp) :: work(1)
Integer, Allocatable :: inc(:)
Character (1) :: dummy(1)
! .. Intrinsic Procedures ..
Intrinsic :: min
! .. Executable Statements ..
Write (nout,*) 'F01BLF Example Program Results'
Write (nout,*)
! Skip heading in data file
Read (nin,*)
Read (nin,*) m, n
lda = m
ldu = n
Allocate (a(lda,n),aijmax(n),d(m),du(n),u(ldu,n),inc(n))
Read (nin,*)(a(i,1:n),i=1,m)
! Set t = eps times norm of A.
norm = 'Frobenius'
anorm = f06raf(norm,m,n,a,lda,work)
t = anorm*x02ajf()
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
Call f01blf(m,n,t,a,lda,aijmax,irank,inc,d,u,ldu,du,ifail)
Write (nout,*) 'Maximum element in A(K) for I.GE.K and J.GE.K'
Write (nout,*)
Write (nout,*) ' K Modulus'
Write (nout,99999)(i,aijmax(i),i=1,min(n,irank+1))
Write (nout,*)
Write (nout,99998) 'Rank = ', irank
Write (nout,*)
Write (nout,99997) 'T = ', t, ' (machine dependent)'
Write (nout,*)
Flush (nout)
! Print the result matrix A.
title = 'Transpose of pseudo-inverse'
ifail = 0
Call x04cbf(matrix,diag,m,n,a,lda,form,title,nolabel,dummy,nolabel, &
dummy,ncols,indent,ifail)
99999 Format (1X,I4,2X,1P,E12.4)
99998 Format (1X,A,I5)
99997 Format (1X,A,1P,E11.4,A)
End Program f01blfe
