概要
本サンプルはFortran言語によりLAPACKルーチンZGGLSEを利用するサンプルプログラムです。
線形等式制約最小二乗問題を解きます。ここで


制約
入力データ
(本ルーチンの詳細はZGGLSE のマニュアルページを参照)| このデータをダウンロード |
ZGGLSE Example Program Data 6 4 2 :Values of M, N and P ( 0.96,-0.81) (-0.03, 0.96) (-0.91, 2.06) (-0.05, 0.41) (-0.98, 1.98) (-1.20, 0.19) (-0.66, 0.42) (-0.81, 0.56) ( 0.62,-0.46) ( 1.01, 0.02) ( 0.63,-0.17) (-1.11, 0.60) ( 0.37, 0.38) ( 0.19,-0.54) (-0.98,-0.36) ( 0.22,-0.20) ( 0.83, 0.51) ( 0.20, 0.01) (-0.17,-0.46) ( 1.47, 1.59) ( 1.08,-0.28) ( 0.20,-0.12) (-0.07, 1.23) ( 0.26, 0.26) :End of matrix A ( 1.00, 0.00) ( 0.00, 0.00) (-1.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 1.00, 0.00) ( 0.00, 0.00) (-1.00, 0.00) :End of matrix B (-2.54, 0.09) ( 1.65,-2.26) (-2.11,-3.96) ( 1.82, 3.30) (-6.41, 3.77) ( 2.07, 0.66) :End of vector c ( 0.00, 0.00) ( 0.00, 0.00) :End of vector d
出力結果
(本ルーチンの詳細はZGGLSE のマニュアルページを参照)| この出力例をダウンロード |
ZGGLSE Example Program Results Constrained least squares solution ( 1.0874,-1.9621) (-0.7409, 3.7297) ( 1.0874,-1.9621) (-0.7409, 3.7297) Square root of the residual sum of squares 1.59E-01
ソースコード
(本ルーチンの詳細はZGGLSE のマニュアルページを参照)※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。
| このソースコードをダウンロード |
Program zgglse_example
! ZGGLSE Example Program Text
! Copyright 2017, Numerical Algorithms Group Ltd. http://www.nag.com
! .. Use Statements ..
Use blas_interfaces, Only: dznrm2
Use lapack_interfaces, Only: zgglse
Use lapack_precision, Only: dp
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: nb = 64, nin = 5, nout = 6
! .. Local Scalars ..
Real (Kind=dp) :: rnorm
Integer :: i, info, lda, ldb, lwork, m, n, p
! .. Local Arrays ..
Complex (Kind=dp), Allocatable :: a(:, :), b(:, :), c(:), d(:), work(:), &
x(:)
! .. Executable Statements ..
Write (nout, *) 'ZGGLSE Example Program Results'
Write (nout, *)
! Skip heading in data file
Read (nin, *)
Read (nin, *) m, n, p
lda = m
ldb = p
lwork = p + n + nb*(m+n)
Allocate (a(lda,n), b(ldb,n), c(m), d(p), work(lwork), x(n))
! Read A, B, C and D from data file
Read (nin, *)(a(i,1:n), i=1, m)
Read (nin, *)(b(i,1:n), i=1, p)
Read (nin, *) c(1:m)
Read (nin, *) d(1:p)
! Solve the equality-constrained least squares problem
! minimize ||c - A*x|| (in the 2-norm) subject to B*x = D
Call zgglse(m, n, p, a, lda, b, ldb, c, d, x, work, lwork, info)
! Print least squares solution
Write (nout, *) 'Constrained least squares solution'
Write (nout, 100) x(1:n)
! Compute the square root of the residual sum of squares
rnorm = dznrm2(m-n+p, c(n-p+1), 1)
Write (nout, *)
Write (nout, *) 'Square root of the residual sum of squares'
Write (nout, 110) rnorm
100 Format (4(' (',F7.4,',',F7.4,')',:))
110 Format (1X, 1P, E10.2)
End Program
