Keyword: 複素行列, 逆行列
概要
本サンプルは複素行列の逆行列を求めるFortranによるサンプルプログラムです。 本サンプルは以下に示される行列Aの逆行列を求めその結果を出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン f07awf() のExampleコードです。本サンプル及びルーチンの詳細情報は f07awf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はf07awf のマニュアルページを参照)| このデータをダウンロード |
F07AWF Example Program Data 4 :Value of N (-1.34, 2.55) ( 0.28, 3.17) (-6.39,-2.20) ( 0.72,-0.92) (-0.17,-1.41) ( 3.31,-0.15) (-0.15, 1.34) ( 1.29, 1.38) (-3.29,-2.39) (-1.91, 4.42) (-0.14,-1.35) ( 1.72, 1.35) ( 2.41, 0.39) (-0.56, 1.47) (-0.83,-0.69) (-1.96, 0.67) :End of matrix A
- 1行目はタイトル行で読み飛ばされます。
- 2行目に行列Aの次数(n)を指定しています。
- 3〜6行目に行列Aの要素を指定しています。
出力結果
(本ルーチンの詳細はf07awf のマニュアルページを参照)| この出力例をダウンロード |
F07AWF Example Program Results
Inverse
1 2 3 4
1 ( 0.0757,-0.4324) ( 1.6512,-3.1342) ( 1.2663, 0.0418) ( 3.8181, 1.1195)
2 (-0.1942, 0.0798) (-1.1900,-0.1426) (-0.2401,-0.5889) (-0.0101,-1.4969)
3 (-0.0957,-0.0491) ( 0.7371,-0.4290) ( 0.3224, 0.0776) ( 0.6887, 0.7891)
4 ( 0.3702,-0.5040) ( 3.7253,-3.1813) ( 1.7014, 0.7267) ( 3.9367, 3.3255)
- 5〜8行目に逆行列が出力されています。
ソースコード
(本ルーチンの詳細はf07awf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
Program f07awfe
! F07AWF Example Program Text
! Mark 24 Release. nAG Copyright 2012.
! .. Use Statements ..
Use nag_library, Only: nag_wp, x04dbf, zgetrf, zgetri
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: nin = 5, nout = 6
! .. Local Scalars ..
Integer :: i, ifail, info, lda, lwork, n
! .. Local Arrays ..
Complex (Kind=nag_wp), Allocatable :: a(:,:), work(:)
Integer, Allocatable :: ipiv(:)
Character (1) :: clabs(1), rlabs(1)
! .. Executable Statements ..
Write (nout,*) 'F07AWF Example Program Results'
! Skip heading in data file
Read (nin,*)
Read (nin,*) n
lda = n
lwork = 64*n
Allocate (a(lda,n),work(lwork),ipiv(n))
! Read A from data file
Read (nin,*)(a(i,1:n),i=1,n)
! Factorize A
! The nAG name equivalent of zgetrf is f07arf
Call zgetrf(n,n,a,lda,ipiv,info)
Write (nout,*)
Flush (nout)
If (info==0) Then
! Compute inverse of A
! The nAG name equivalent of zgetri is f07awf
Call zgetri(n,a,lda,ipiv,work,lwork,info)
! Print inverse
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
Call x04dbf('General',' ',n,n,a,lda,'Bracketed','F7.4','Inverse', &
'Integer',rlabs,'Integer',clabs,80,0,ifail)
Else
Write (nout,*) 'The factor U is singular'
End If
End Program f07awfe
