File: TB01VY.f

package info (click to toggle)
dynare 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,640 kB
  • sloc: fortran: 82,231; cpp: 72,734; ansic: 28,874; pascal: 13,241; sh: 4,300; objc: 3,281; yacc: 2,833; makefile: 1,288; lex: 1,162; python: 162; lisp: 54; xml: 8
file content (317 lines) | stat: -rw-r--r-- 10,298 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
      SUBROUTINE TB01VY( APPLY, N, M, L, THETA, LTHETA, A, LDA, B, LDB,
     $                   C, LDC, D, LDD, X0, DWORK, LDWORK, INFO )
C
C     SLICOT RELEASE 5.0.
C
C     Copyright (c) 2002-2009 NICONET e.V.
C
C     This program is free software: you can redistribute it and/or
C     modify it under the terms of the GNU General Public License as
C     published by the Free Software Foundation, either version 2 of
C     the License, or (at your option) any later version.
C
C     This program is distributed in the hope that it will be useful,
C     but WITHOUT ANY WARRANTY; without even the implied warranty of
C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
C     GNU General Public License for more details.
C
C     You should have received a copy of the GNU General Public License
C     along with this program.  If not, see
C     <http://www.gnu.org/licenses/>.
C
C     PURPOSE
C
C     To convert the linear discrete-time system given as its output
C     normal form [1], with parameter vector THETA, into the state-space
C     representation (A, B, C, D), with the initial state x0.
C
C     ARGUMENTS
C
C     Mode Parameters
C
C     APPLY   CHARACTER*1
C             Specifies whether or not the parameter vector should be
C             transformed using a bijective mapping, as follows:
C             = 'A' : apply the bijective mapping to the N vectors in
C                     THETA corresponding to the matrices A and C;
C             = 'N' : do not apply the bijective mapping.
C             The transformation performed when APPLY = 'A' allows
C             to get rid of the constraints norm(THETAi) < 1, i = 1:N.
C             A call of the SLICOT Library routine TB01VD associated to
C             a call of TB01VY must use the same value of APPLY.
C
C     Input/Output Parameters
C
C     N       (input) INTEGER
C             The order of the system.  N >= 0.
C
C     M       (input) INTEGER
C             The number of system inputs.  M >= 0.
C
C     L       (input) INTEGER
C             The number of system outputs.  L >= 0.
C
C     THETA   (input) DOUBLE PRECISION array, dimension (LTHETA)
C             The leading N*(L+M+1)+L*M part of this array must contain
C             the parameter vector that defines a system (A, B, C, D),
C             with the initial state x0. The parameters are:
C
C             THETA(1:N*L)                      : parameters for A, C;
C             THETA(N*L+1:N*(L+M))              : parameters for B;
C             THETA(N*(L+M)+1:N*(L+M)+L*M)      : parameters for D;
C             THETA(N*(L+M)+L*M+1:N*(L+M+1)+L*M): parameters for x0.
C
C     LTHETA  INTEGER
C             The length of array THETA.  LTHETA >= N*(L+M+1)+L*M.
C
C     A       (output) DOUBLE PRECISION array, dimension (LDA,N)
C             The leading N-by-N part of this array contains the system
C             state matrix corresponding to the output normal form with
C             parameter vector THETA.
C
C     LDA     INTEGER
C             The leading dimension of array A.  LDA >= MAX(1,N).
C
C     B       (output) DOUBLE PRECISION array, dimension (LDB,M)
C             The leading N-by-M part of this array contains the system
C             input matrix corresponding to the output normal form with
C             parameter vector THETA.
C
C     LDB     INTEGER
C             The leading dimension of array B.  LDB >= MAX(1,N).
C
C     C       (output) DOUBLE PRECISION array, dimension (LDC,N)
C             The leading L-by-N part of this array contains the system
C             output matrix corresponding to the output normal form with
C             parameter vector THETA.
C
C     LDC     INTEGER
C             The leading dimension of array C.  LDC >= MAX(1,L).
C
C     D       (output) DOUBLE PRECISION array, dimension (LDD,M)
C             The leading L-by-M part of this array contains the system
C             input/output matrix corresponding to the output normal
C             form with parameter vector THETA.
C
C     LDD     INTEGER
C             The leading dimension of array D.  LDD >= MAX(1,L).
C
C     X0      (output) DOUBLE PRECISION array, dimension (N)
C             This array contains the initial state of the system, x0,
C             corresponding to the output normal form with parameter
C             vector THETA.
C
C     Workspace
C
C     DWORK   DOUBLE PRECISION array, dimension (LDWORK)
C
C     LDWORK  INTEGER
C             The length of the array DWORK.
C             LDWORK >= N*(N+L+1).
C
C     Error Indicator
C
C     INFO    INTEGER
C             = 0:  successful exit;
C             < 0:  if INFO = -i, the i-th argument had an illegal
C                   value.
C
C     METHOD
C
C     The parameters characterizing A and C are used to build N
C     orthogonal transformations, which are then applied to recover
C     these matrices.
C
C     CONTRIBUTORS
C
C     A. Riedel, R. Schneider, Chemnitz University of Technology,
C     Oct. 2000, during a stay at University of Twente, NL.
C
C     REVISIONS
C
C     V. Sima, Research Institute for Informatics, Bucharest, Mar. 2001,
C     Feb. 2002, Feb. 2004.
C
C     KEYWORDS
C
C     Asymptotically stable, output normal form, parameter estimation,
C     similarity transformation.
C
C     ******************************************************************
C
C     .. Parameters ..
      DOUBLE PRECISION  ZERO, ONE, HALF
      PARAMETER         ( ZERO = 0.0D0, ONE = 1.0D0, HALF = 0.5D0 )
C     .. Scalar Arguments ..
      CHARACTER         APPLY
      INTEGER           INFO, L, LDA, LDB, LDC, LDD, LDWORK, LTHETA, M,
     $                  N
C     .. Array Arguments ..
      DOUBLE PRECISION  A(LDA,*), B(LDB,*), C(LDC,*), D(LDD,*),
     $                  DWORK(*), THETA(*), X0(*)
C     .. Local Scalars ..
      DOUBLE PRECISION  FACTOR, RI, TI, TOBYPI
      INTEGER           CA, JWORK, I, IN, J, K, LDCA
      LOGICAL           LAPPLY
C     .. External Functions ..
      EXTERNAL          DNRM2, LSAME
      DOUBLE PRECISION  DNRM2
      LOGICAL           LSAME
C     .. External Subroutines ..
      EXTERNAL          DAXPY, DCOPY, DGEMV, DGER, DLACPY, DSCAL,
     $                  XERBLA
C     .. Intrinsic Functions ..
      INTRINSIC         ATAN, MAX, SQRT
C     ..
C     .. Executable Statements ..
C
C     Check the scalar input parameters.
C
      LAPPLY = LSAME( APPLY, 'A' )
C
      INFO = 0
      IF ( .NOT.( LAPPLY .OR. LSAME( APPLY, 'N' ) ) ) THEN
         INFO = -1
      ELSEIF ( N.LT.0 ) THEN
         INFO = -2
      ELSEIF ( M.LT.0 ) THEN
         INFO = -3
      ELSEIF ( L.LT.0 ) THEN
         INFO = -4
      ELSEIF ( LTHETA.LT.( N*( L + M + 1 ) + L*M ) ) THEN
         INFO = -6
      ELSEIF ( LDA.LT.MAX( 1, N ) ) THEN
         INFO = -8
      ELSEIF ( LDB.LT.MAX( 1, N ) ) THEN
         INFO = -10
      ELSEIF ( LDC.LT.MAX( 1, L ) ) THEN
         INFO = -12
      ELSEIF ( LDD.LT.MAX( 1, L ) ) THEN
         INFO = -14
      ELSEIF ( LDWORK.LT.N*( N + L + 1 ) ) THEN
         INFO = -17
      ENDIF
C
C     Return if there are illegal arguments.
C
      IF( INFO.NE.0 ) THEN
         CALL XERBLA( 'TB01VY', -INFO )
         RETURN
      ENDIF
C
C     Quick return if possible.
C
      IF ( MAX( N, M, L ).EQ.0 )
     $   RETURN
C
      IF ( M.GT.0 ) THEN
C
C        Copy the matrix B from THETA.
C
         CALL DLACPY( 'Full', N, M, THETA(N*L+1), N, B, LDB )
C
C        Copy the matrix D.
C
         CALL DLACPY( 'Full', L, M, THETA(N*(L+M)+1), L, D, LDD )
      ENDIF
C
      IF ( N.EQ.0 ) THEN
         RETURN
      ELSE IF ( L.EQ.0 ) THEN
         CALL DCOPY( N, THETA(N*M+1), 1, X0, 1 )
         RETURN
      END IF
C
C     Initialize the indices in the workspace.
C
      LDCA = N + L
C
      CA = 1
C
      JWORK  = CA + N*LDCA
      TOBYPI = HALF/ATAN( ONE )
C
C     Generate the matrices C and A from their parameters.
C     Start with the block matrix [0; I], where 0 is a block of zeros
C     of size L-by-N, and I is the identity matrix of order N.
C
      DWORK(CA) = ZERO
      CALL DCOPY( N*(L+N), DWORK(CA), 0, DWORK(CA), 1 )
      DWORK(CA+L) = ONE
      CALL DCOPY( N, DWORK(CA+L), 0, DWORK(CA+L), LDCA+1 )
C
C     Now, read out THETA(1 : N*L) and perform the transformations
C     defined by the parameters in THETA.
C
      DO 30 I = N, 1, -1
C
C        Save THETAi in the first column of C and use the copy for
C        further processing.
C
         CALL DCOPY( L, THETA((I-1)*L+1), 1, C, 1 )
         TI = DNRM2( L, C, 1 )
         IF ( LAPPLY .AND. TI.NE.ZERO ) THEN
C
C           Apply the bijective mapping which guarantees that TI < 1.
C
            FACTOR = TOBYPI*ATAN( TI )/TI
C
C           Scale THETAi and apply the same scaling on TI.
C
            CALL DSCAL( L, FACTOR, C, 1 )
            TI = TI*FACTOR
         END IF
C
C        RI = sqrt( 1 - TI**2 ).
C
         RI = SQRT( ( ONE - TI )*( ONE + TI ) )
C
C        Multiply a certain part of DWORK(CA) with Ui' from the left,
C        where Ui = [ -THETAi, Si; RI, THETAi' ] is (L+1)-by-(L+1), but
C        Ui is not stored.
C
         CALL DGEMV( 'Transpose', L, N, -ONE, DWORK(CA+N-I), LDCA, C, 1,
     $               ZERO, DWORK(JWORK), 1 )
C
         IF ( TI.GT.ZERO ) THEN
            CALL DGER( L, N, (ONE-RI)/TI/TI, C, 1, DWORK(JWORK), 1,
     $                 DWORK(CA+N-I), LDCA )
         ELSE
C
C           The call below is for the limiting case.
C
            CALL DGER( L, N, HALF, C, 1, DWORK(JWORK), 1,
     $                 DWORK(CA+N-I), LDCA )
         ENDIF
C
         CALL DGER( L, N, ONE, C, 1, DWORK(CA+N-I+L), LDCA,
     $              DWORK(CA+N-I), LDCA )
         CALL DAXPY( N, RI, DWORK(CA+N-I+L), LDCA, DWORK(JWORK), 1 )
C
C        Move these results to their appropriate locations.
C
         DO 20 J = 1, N
            IN = CA + N - I + ( J - 1 )*LDCA
            DO 10 K = IN + L, IN + 1, -1
               DWORK(K) = DWORK(K-1)
   10       CONTINUE
            DWORK(IN) = DWORK(JWORK+J-1)
   20    CONTINUE
C
   30 CONTINUE
C
C     Now, DWORK(CA) = [C; A]. Copy to C and A.
C
      DO 40 I = 1, N
         CALL DCOPY( L, DWORK(CA+(I-1)*LDCA),   1, C(1,I), 1 )
         CALL DCOPY( N, DWORK(CA+L+(I-1)*LDCA), 1, A(1,I), 1 )
   40 CONTINUE
C
C     Copy the initial state x0.
C
      CALL DCOPY( N, THETA(N*(L+M)+L*M+1), 1, X0, 1 )
C
      RETURN
C
C *** Last line of TB01VY ***
      END