Keyword: Gauss-Markov, GLM, 線形モデル
概要
本サンプルは実一般Gauss-Markov線形モデル(GLM)問題を解くFortranによるサンプルプログラムです。 本サンプルは以下に示される実一般Gauss-Markov線形モデル(GLM)問題を解いて解を出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン f08zbf() のExampleコードです。本サンプル及びルーチンの詳細情報は f08zbf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はf08zbf のマニュアルページを参照)| このデータをダウンロード |
F08ZBF Example Program Data 4 3 4 :Values of M, N and P -0.57 -1.28 -0.39 -1.93 1.08 -0.31 2.30 0.24 -0.40 -0.02 1.03 -1.43 :End of matrix A 0.50 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 2.00 0.00 0.00 0.00 0.00 5.00 :End of matrix B 1.32 -4.00 5.52 3.24 :End of vector d
- 1行目はタイトル行で読み飛ばされます。
- 3行目に行列Aと行列Bの行数(m)、行列Aの列数(n)、行列Bの列数(p)を指定しています。
- 5〜8行目に行列Aの要素を指定しています。
- 10〜13行目に行列Bの要素を指定しています。
- 15〜18行目にベクトルdの要素を指定しています。
出力結果
(本ルーチンの詳細はf08zbf のマニュアルページを参照)| この出力例をダウンロード |
F08ZBF Example Program Results
Weighted least-squares solution
1.9889 -1.0058 -2.9911
Residual vector
-6.37E-04 -2.45E-03 -4.72E-03 7.70E-03
Square root of the residual sum of squares
9.38E-03
- 4行目に重みつき最小二乗問題の解が出力されています。
- 7行目に残差ベクトルが出力されています。
- 10行目に残差平方和の平方根が出力されています。
ソースコード
(本ルーチンの詳細はf08zbf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM f08zbfe
! F08ZBF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : dggglm, dnrm2, nag_wp
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: nb = 64, nin = 5, nout = 6
! .. Local Scalars ..
REAL (KIND=nag_wp) :: rnorm
INTEGER :: i, info, lda, ldb, lwork, m, n, p
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:,:), d(:), work(:), x(:), &
y(:)
! .. Executable Statements ..
WRITE (nout,*) 'F08ZBF Example Program Results'
WRITE (nout,*)
! Skip heading in data file
READ (nin,*)
READ (nin,*) m, n, p
lda = m
ldb = m
lwork = n + m + nb*(m+p)
ALLOCATE (a(lda,n),b(ldb,p),d(m),work(lwork),x(n),y(p))
! Read A, B and D from data file
READ (nin,*) (a(i,1:n),i=1,m)
READ (nin,*) (b(i,1:p),i=1,m)
READ (nin,*) d(1:m)
! Solve the weighted least squares problem
! minimize ||inv(B)*(d - A*x)|| (in the 2-norm)
! The nAG name equivalent of dggglm is f08zbf
CALL dggglm(m,n,p,a,lda,b,ldb,d,x,y,work,lwork,info)
! Print least squares solution, x
WRITE (nout,*) 'Weighted least-squares solution'
WRITE (nout,99999) x(1:n)
! Print residual vector y = inv(B)*(d - A*x)
WRITE (nout,*)
WRITE (nout,*) 'Residual vector'
WRITE (nout,99998) y(1:p)
! Compute and print the square root of the residual sum of
! squares
! The nAG name equivalent of dnrm2 is f06ejf
rnorm = dnrm2(p,y,1)
WRITE (nout,*)
WRITE (nout,*) 'Square root of the residual sum of squares'
WRITE (nout,99998) rnorm
99999 FORMAT (1X,7F11.4)
99998 FORMAT (3X,1P,7E11.2)
END PROGRAM f08zbfe
