Keyword: 最近傍相関行列
概要
本サンプルは最近傍相関行列の計算を行うFortranによるサンプルプログラムです。 本サンプルは以下に示される行列に対して最近傍相関行列の計算を行います。
※本サンプルはnAG Fortranライブラリに含まれるルーチン g02aaf() のExampleコードです。本サンプル及びルーチンの詳細情報は g02aaf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はg02aaf のマニュアルページを参照)| このデータをダウンロード |
G02AAF Example Program Data 4 :: N 2.0 -1.0 0.0 0.0 -1.0 2.0 -1.0 0.0 0.0 -1.0 2.0 -1.0 0.0 0.0 -1.0 2.0 :: End of G
- 1行目はタイトル行で読み飛ばされます。
- 2行目は行列のサイズ(n)を指定しています。
- 3行目〜6行目は初期行列(g)を指定しています。
出力結果
(本ルーチンの詳細はg02aaf のマニュアルページを参照)| この出力例をダウンロード |
G02AAF Example Program Results
Nearest Correlation Matrix
1 2 3 4
1 1.0000 -0.8084 0.1916 0.1068
2 -0.8084 1.0000 -0.6562 0.1916
3 0.1916 -0.6562 1.0000 -0.8084
4 0.1068 0.1916 -0.8084 1.0000
Number of Newton steps taken: 3
Number of function evaluations: 4
- 3〜8行目に最近傍相関行列が出力されています。
- 10行目に実行されたニュートンステップの数が出力されています。
- 11行目に関数評価の数が出力されています。
ソースコード
(本ルーチンの詳細はg02aaf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM g02aafe
! G02AAF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : g02aaf, nag_wp, x04caf
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: nin = 5, nout = 6
! .. Local Scalars ..
REAL (KIND=nag_wp) :: errtol, nrmgrd
INTEGER :: feval, i, ifail, iter, ldg, ldx, &
maxit, maxits, n
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: g(:,:), x(:,:)
! .. Executable Statements ..
WRITE (nout,*) 'G02AAF Example Program Results'
WRITE (nout,*)
FLUSH (nout)
! Skip heading in data file
READ (nin,*)
! Read in the problem size
READ (nin,*) n
ldg = n
ldx = n
ALLOCATE (g(ldg,n),x(ldx,n))
! Read in the matrix G
READ (nin,*) (g(i,1:n),i=1,n)
! Use the defaults for ERRTOL, MAXITS and MAXIT
errtol = 0.0E0_nag_wp
maxits = 0
maxit = 0
! Calculate nearest correlation matrix
ifail = 0
CALL g02aaf(g,ldg,n,errtol,maxits,maxit,x,ldx,iter,feval,nrmgrd,ifail)
! Display results
ifail = 0
CALL x04caf('General',' ',n,n,x,ldx,'Nearest Correlation Matrix',ifail)
WRITE (nout,*)
WRITE (nout,99999) ' Number of Newton steps taken:', iter
WRITE (nout,99998) ' Number of function evaluations:', feval
99999 FORMAT (1X,A,I11)
99998 FORMAT (1X,A,I9)
END PROGRAM g02aafe
