複素一般化線形最小二乗: 線形等式制約

LAPACKサンプルソースコード : 使用ルーチン名:ZGGLSE

概要

本サンプルはFortran言語によりLAPACKルーチンZGGLSEを利用するサンプルプログラムです。

線形等式制約最小二乗問題を解きます。

\begin{displaymath}
\min_{x} \left\Vert c - A x \right\Vert _{2} \: \mbox{ subject to } \: B x = d
\end{displaymath}

ここで

\begin{displaymath}
A = \left(
\begin{array}{rrrr}
0.96 - 0.81 i & -0.03 + 0....
...12 i & -0.07 + 1.23 i & 0.26 + 0.26 i
\end{array} \right), \:
\end{displaymath}


\begin{displaymath}
B = \left(
\begin{array}{rrrr}
1 & 0 & -1 & 0 \\
0 & 1 ...
...
d = \left(
\begin{array}{r}
0 \\
0
\end{array} \right).
\end{displaymath}

制約 $ B x = d$$ x_{1} = x_{3}$$ x_{2} = x_{4}$に対応します。

入力データ

(本ルーチンの詳細はZGGLSE のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

このデータをダウンロード
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 のマニュアルページを参照)
1
2
3
4
5
6
7

この出力例をダウンロード
 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 のマニュアルページを参照)

※本サンプルソースコードのご利用手順は「サンプルのコンパイル及び実行方法」をご参照下さい。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

このソースコードをダウンロード
    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


ご案内
関連情報
© 日本ニューメリカルアルゴリズムズグループ株式会社 2025
Privacy Policy  /  Trademarks