File: MB03YT.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 (331 lines) | stat: -rw-r--r-- 10,220 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
      SUBROUTINE MB03YT( A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, CSL, SNL,
     $                   CSR, SNR )
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 compute the periodic Schur factorization of a real 2-by-2
C     matrix pair (A,B) where B is upper triangular. This routine
C     computes orthogonal (rotation) matrices given by CSL, SNL and CSR,
C     SNR such that
C
C     1) if the pair (A,B) has two real eigenvalues, then
C
C        [ a11 a12 ] := [  CSL  SNL ] [ a11 a12 ] [  CSR -SNR ]
C        [  0  a22 ]    [ -SNL  CSL ] [ a21 a22 ] [  SNR  CSR ]
C
C        [ b11 b12 ] := [  CSR  SNR ] [ b11 b12 ] [  CSL -SNL ]
C        [  0  b22 ]    [ -SNR  CSR ] [  0  b22 ] [  SNL  CSL ],
C
C     2) if the pair (A,B) has a pair of complex conjugate eigenvalues,
C        then
C
C        [ a11 a12 ] := [  CSL  SNL ] [ a11 a12 ] [  CSR -SNR ]
C        [ a21 a22 ]    [ -SNL  CSL ] [ a21 a22 ] [  SNR  CSR ]
C
C        [ b11  0  ] := [  CSR  SNR ] [ b11 b12 ] [  CSL -SNL ]
C        [  0  b22 ]    [ -SNR  CSR ] [  0  b22 ] [  SNL  CSL ].
C
C     This is a modified version of the LAPACK routine DLAGV2 for
C     computing the real, generalized Schur decomposition of a
C     two-by-two matrix pencil.
C
C     ARGUMENTS
C
C     Input/Output Parameters
C
C     A       (input/output) DOUBLE PRECISION array, dimension (LDA,2)
C             On entry, the leading 2-by-2 part of this array must
C             contain the matrix A.
C             On exit, the leading 2-by-2 part of this array contains
C             the matrix A of the pair in periodic Schur form.
C
C     LDA     INTEGER
C             The leading dimension of the array A.  LDA >= 2.
C
C     B       (input/output) DOUBLE PRECISION array, dimension (LDB,2)
C             On entry, the leading 2-by-2 part of this array must
C             contain the upper triangular matrix B.
C             On exit, the leading 2-by-2 part of this array contains
C             the matrix B of the pair in periodic Schur form.
C
C     LDB     INTEGER
C             The leading dimension of the array B.  LDB >= 2.
C
C     ALPHAR  (output) DOUBLE PRECISION array, dimension (2)
C     ALPHAI  (output) DOUBLE PRECISION array, dimension (2)
C     BETA    (output) DOUBLE PRECISION array, dimension (2)
C             (ALPHAR(k)+i*ALPHAI(k))*BETA(k) are the eigenvalues of the
C             pair (A,B), k=1,2, i = sqrt(-1). ALPHAI(1) >= 0.
C
C     CSL     (output) DOUBLE PRECISION
C             The cosine of the first rotation matrix.
C
C     SNL     (output) DOUBLE PRECISION
C             The sine of the first rotation matrix.
C
C     CSR     (output) DOUBLE PRECISION
C             The cosine of the second rotation matrix.
C
C     SNR     (output) DOUBLE PRECISION
C             The sine of the second rotation matrix.
C
C     REFERENCES
C
C     [1] Van Loan, C.
C         Generalized Singular Values with Algorithms and Applications.
C         Ph. D. Thesis, University of Michigan, 1973.
C
C     CONTRIBUTORS
C
C     D. Kressner, Technical Univ. Berlin, Germany, and
C     P. Benner, Technical Univ. Chemnitz, Germany, December 2003.
C
C     REVISIONS
C
C     V. Sima, June 2008 (SLICOT version of the HAPACK routine DLAPV2).
C     V. Sima, July 2008, May 2009.
C
C     KEYWORDS
C
C     Eigenvalue, periodic Schur form
C
C     ******************************************************************
C
C     .. Parameters ..
      DOUBLE PRECISION  ZERO, ONE
      PARAMETER         ( ZERO = 0.0D0, ONE = 1.0D0 )
C     .. Scalar Arguments ..
      INTEGER           LDA, LDB
      DOUBLE PRECISION  CSL, CSR, SNL, SNR
C     .. Array Arguments ..
      DOUBLE PRECISION  A(LDA,*), ALPHAI(2), ALPHAR(2), B(LDB,*),
     $                  BETA(2)
C     .. Local Scalars ..
      DOUBLE PRECISION  ANORM, BNORM, H1, H2, H3, QQ, R, RR, SAFMIN,
     $                  SCALE1, SCALE2, T, ULP, WI, WR1, WR2
C     .. External Functions ..
      DOUBLE PRECISION  DLAMCH, DLAPY2
      EXTERNAL          DLAMCH, DLAPY2
C     .. External Subroutines ..
      EXTERNAL          DLAG2, DLARTG, DLASV2, DROT
C     .. Intrinsic Functions ..
      INTRINSIC         ABS, MAX
C
C     .. Executable Statements ..
C
      SAFMIN = DLAMCH( 'S' )
      ULP    = DLAMCH( 'P' )
C
C     Scale A.
C
      ANORM = MAX( ABS( A(1,1) ) + ABS( A(2,1) ),
     $             ABS( A(1,2) ) + ABS( A(2,2) ), SAFMIN )
      A(1,1) = A(1,1) / ANORM
      A(1,2) = A(1,2) / ANORM
      A(2,1) = A(2,1) / ANORM
      A(2,2) = A(2,2) / ANORM
C
C     Scale B.
C
      BNORM = MAX( ABS( B(1,1) ), ABS( B(1,2) ) + ABS( B(2,2) ), SAFMIN)
      B(1,1) = B(1,1) / BNORM
      B(1,2) = B(1,2) / BNORM
      B(2,2) = B(2,2) / BNORM
C
C     Check if A can be deflated.
C
      IF ( ABS( A(2,1) ).LE.ULP ) THEN
         CSL = ONE
         SNL = ZERO
         CSR = ONE
         SNR = ZERO
         WI  = ZERO
         A(2,1) = ZERO
         B(2,1) = ZERO
C
C     Check if B is singular.
C
      ELSE IF ( ABS( B(1,1) ).LE.ULP ) THEN
         CALL DLARTG( A(2,2), A(2,1), CSR, SNR, T )
         SNR = -SNR
         CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )
         CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSR, SNR )
         CSL = ONE
         SNL = ZERO
         WI  = ZERO
         A(2,1) = ZERO
         B(1,1) = ZERO
         B(2,1) = ZERO
      ELSE IF( ABS( B(2,2) ).LE.ULP ) THEN
         CALL DLARTG( A(1,1), A(2,1), CSL, SNL, R )
         CSR = ONE
         SNR = ZERO
         WI  = ZERO
         CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )
         CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSL, SNL )
         A(2,1) = ZERO
         B(2,1) = ZERO
         B(2,2) = ZERO
      ELSE
C
C        B is nonsingular, first compute the eigenvalues of A / adj(B).
C
         R = B(1,1)
         B(1,1) = B(2,2)
         B(2,2) = R
         B(1,2) = -B(1,2)
         CALL DLAG2( A, LDA, B, LDB, SAFMIN, SCALE1, SCALE2, WR1, WR2,
     $               WI )
C
         IF( WI.EQ.ZERO ) THEN
C
C           Two real eigenvalues, compute s*A-w*B.
C
            H1 = SCALE1*A(1,1) - WR1*B(1,1)
            H2 = SCALE1*A(1,2) - WR1*B(1,2)
            H3 = SCALE1*A(2,2) - WR1*B(2,2)
C
            RR = DLAPY2( H1, H2 )
            QQ = DLAPY2( SCALE1*A(2,1), H3 )
C
            IF ( RR.GT.QQ ) THEN
C
C              Find right rotation matrix to zero 1,1 element of
C              (sA - wB).
C
               CALL DLARTG( H2, H1, CSR, SNR, T )
C
            ELSE
C
C              Find right rotation matrix to zero 2,1 element of
C              (sA - wB).
C
               CALL DLARTG( H3, SCALE1*A(2,1), CSR, SNR, T )
C
            END IF
C
            SNR = -SNR
            CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )
            CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSR, SNR )
C
C           Compute inf norms of A and B.
C
            H1 = MAX( ABS( A(1,1) ) + ABS( A(1,2) ),
     $                ABS( A(2,1) ) + ABS( A(2,2) ) )
            H2 = MAX( ABS( B(1,1) ) + ABS( B(1,2) ),
     $                ABS( B(2,1) ) + ABS( B(2,2) ) )
C
            IF( ( SCALE1*H1 ).GE.ABS( WR1 )*H2 ) THEN
C
C              Find left rotation matrix Q to zero out B(2,1).
C
               CALL DLARTG( B(1,1), B(2,1), CSL, SNL, R )
C
            ELSE
C
C              Find left rotation matrix Q to zero out A(2,1).
C
               CALL DLARTG( A(1,1), A(2,1), CSL, SNL, R )
C
            END IF
C
            CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )
            CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSL, SNL )
C
            A(2,1) = ZERO
            B(2,1) = ZERO
C
C           Re-adjoint B.
C
            R = B(1,1)
            B(1,1) = B(2,2)
            B(2,2) = R
            B(1,2) = -B(1,2)
C
         ELSE
C
C           A pair of complex conjugate eigenvalues:
C           first compute the SVD of the matrix adj(B).
C
            R = B(1,1)
            B(1,1) = B(2,2)
            B(2,2) = R
            B(1,2) = -B(1,2)
            CALL DLASV2( B(1,1), B(1,2), B(2,2), R, T, SNL, CSL,
     $                   SNR, CSR )
C
C           Form (A,B) := Q(A,adj(B))Z' where Q is left rotation matrix
C           and Z is right rotation matrix computed from DLASV2.
C
            CALL DROT( 2, A(1,1), LDA, A(2,1), LDA, CSL, SNL )
            CALL DROT( 2, B(1,1), LDB, B(2,1), LDB, CSR, SNR )
            CALL DROT( 2, A(1,1), 1, A(1,2), 1, CSR, SNR )
            CALL DROT( 2, B(1,1), 1, B(1,2), 1, CSL, SNL )
C
            B(2,1) = ZERO
            B(1,2) = ZERO
         END IF
C
      END IF
C
C     Unscaling
C
      R = B(1,1)
      T = B(2,2)
      A(1,1) = ANORM*A(1,1)
      A(2,1) = ANORM*A(2,1)
      A(1,2) = ANORM*A(1,2)
      A(2,2) = ANORM*A(2,2)
      B(1,1) = BNORM*B(1,1)
      B(2,1) = BNORM*B(2,1)
      B(1,2) = BNORM*B(1,2)
      B(2,2) = BNORM*B(2,2)
C
      IF( WI.EQ.ZERO ) THEN
         ALPHAR(1) = A(1,1)
         ALPHAR(2) = A(2,2)
         ALPHAI(1) = ZERO
         ALPHAI(2) = ZERO
         BETA(1) = B(1,1)
         BETA(2) = B(2,2)
      ELSE
         WR1 = ANORM*WR1
         WI  = ANORM*WI
         IF ( ABS( WR1 ).GT.ONE .OR. WI.GT.ONE ) THEN
            WR1 = WR1*R
            WI = WI*R
            R = ONE
         END IF
         IF ( ABS( WR1 ).GT.ONE .OR. ABS( WI ).GT.ONE ) THEN
            WR1 = WR1*T
            WI = WI*T
            T = ONE
         END IF
         ALPHAR(1) = ( WR1 / SCALE1 )*R*T
         ALPHAI(1) = ABS( ( WI  / SCALE1 )*R*T )
         ALPHAR(2) =  ALPHAR(1)
         ALPHAI(2) = -ALPHAI(1)
         BETA(1) = BNORM
         BETA(2) = BNORM
      END IF
      RETURN
C *** Last line of MB03YT ***
      END