File: lybsc.f

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (337 lines) | stat: -rw-r--r-- 9,126 bytes parent folder | download | duplicates (5)
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
332
333
334
335
336
337
      subroutine lybsc(n,a,na,c,x,u,eps,wrk,mode,ierr)
      integer n,na,mode,ierr
      double precision a(na,n),c(na,n),x(na,n),u(na,n),wrk(n)
      double precision eps
C
C! calling sequence
C        subroutine lybsc(n,a,na,c,x,u,wrk,mode,ierr)
C
C        integer n,na,mode,ierr
C        double precision a(na,n),c(na,n),x(na,n),u(na,n),wrk(n)
C
C arguments in
C
C
C       n        integer
C                -the dimension of a
C
C       a        double precision(n,n)
C                -coefficient matrix of the equation
C                *** n.b. in this routine  a  is overwritten with
C                its transformed upper triangular form (see comments)
C
C       c        double precision(n,n)
C                -coefficient matrix of the equation
C
C       na       integer
C                -the declared first dimension of a,c,x and u
C
C       mode     integer
C                - mode = 0  if  a  has not already been reduced to
C                                upper triangular form
C                - mode = 1  if  a  has been reduced to triangular form
C                                by (e.g) a previous call to lybsc
C
C arguments out
C
C       a        double precision(n,n)
C                -on exit, a  contains the transformed upper triangular
C                form of a
C
C       x        double precision(n,n)
C                -the solution matrix
C
C       u        double precision(n,n)
C                - u  contains the orthogonal matrix which was used
C                to reduce  a  to upper triangular form
C
C       ierr     integer
C                -error indicator
C
C                ierr = 0     successful return
C
C                ierr = 1     a  has a degenerate pair of eigenvalues
C
C                ierr = 2     a  cannot be reduced to triangular form
C
C working space
C
C        wrk     double precision(n)
C
C!purpose
C
C        to solve the double precision matrix equation
C
C               trans(a)*x + x*a = c
C
C        where  c  is symmetric, and  trans(a)  denotes
C        the transpose of  a .
C
C!method
C
C        this routine is a modification of the subroutine  atxxac,
C        written and discussed by  r.h.bartels & g.w.stewart.
C
C!reference
C
C         r.h. bartels & g.w. stewart
C            "solution of the matrix equation  a'x + xb = c  ",
C            commun. a.c.m., vol 15, 1972, pp. 820-826 .
C
C!auxiliary routines
C
C       orthes,ortran (eispack)
C       sgefa,sgesl   (linpack)
C       lycsr  (slice)
C
C!origin: adapted from
C
C                control systems research group, dept eecs, kingston
C                polytechnic, penrhyn rd.,kingston-upon-thames, england.
C
C!
C******************************************************************
C       local variables:
C
      integer i,j,k
      double precision dprec,tt(1)
C
      if (mode .eq. 1) goto 10
      call orthes(na,n,1,n,a,wrk)
      call ortran(na,n,1,n,a,wrk,u)
      call hqror2(na,n,1,n,a,tt,tt,u,ierr,11)
      if (ierr .ne. 0) goto 140
 10   continue
      do 20 i = 1,n
        do 15 j = 1,n
          x(i,j) = c(i,j)
 15     continue
        x(i,i) = x(i,i) * 0.50d+0
 20   continue
C
      do 40 i = 1,n
        do 30 j = 1,n
          dprec = 0.0d+0
          do 25 k = i,n
            dprec = dprec + x(i,k)*u(k,j)
 25       continue
          wrk(j) = dprec
 30     continue
        do 40 j = 1,n
          x(i,j) = wrk(j)
 40   continue
      do 60 j = 1,n
        do 50 i = 1,n
          dprec = 0.0d+0
          do 45 k = 1,n
            dprec = dprec + u(k,i)*x(k,j)
 45       continue
          wrk(i) = dprec
 50     continue
        do 60 i = 1,n
          x(i,j) = wrk(i)
 60   continue
C
      do 70 i = 1,n
        do 70 j = i,n
          x(i,j) = x(i,j) + x(j,i)
          x(j,i) = x(i,j)
 70   continue
C
C     call shrslv (c,a,x,n,n,na,na,na,0.0d+0,1.0d+20,fail)
      call lycsr(n,a,na,x,ierr)
      if (ierr .ne. 0) return
C
      do 80 i = 1,n
        x(i,i) = x(i,i) * 0.50d+0
 80   continue
C
      do 100 i = 1,n
        do 90 j = 1,n
          dprec = 0.0d+0
          do 85 k = i,n
            dprec = dprec + x(i,k)*u(j,k)
 85       continue
          wrk(j) = dprec
 90     continue
        do 100 j = 1,n
          x(i,j) = wrk(j)
 100  continue
C
      do 120 j = 1,n
        do 110 i = 1,n
          dprec = 0.0d+0
          do 105 k = 1,n
            dprec = dprec + u(i,k)*x(k,j)
 105      continue
          wrk(i) = dprec
 110    continue
        do 120 i = 1,n
          x(i,j) = wrk(i)
 120  continue
C
      do 130 i = 1,n
        do 130 j = i,n
          x(i,j) = x(i,j) + x(j,i)
          x(j,i) = x(i,j)
 130  continue
C
      goto 150
 140  ierr = 2
 150  return
      end
      subroutine lycsr(n,a,na,c,ierr)
c%calling sequence
c      subroutine lycsr(n,a,na,c,ierr)
c     integer n,na,ierr
c     double precision a(na,n),c(na,n)
c%purpose
c
c
c     this routine solves the continuous lyapunov equation where
c     the matrix  a  has been transformed to quasi-triangular form.
c
c     this routine is intended to be called only from
c            slice   routine  lybsc .
c%
      integer i,j,k,l,n,dk,dl,ia,kk,ll,na,job,km1,ldl,ierr,info,
     x        ldim,nsys,ipvt(4)
      double precision a(na,n),c(na,n)
      double precision t(4,4),p(4)
      double precision dprec
      ierr = 0
      ldim = 4
      job = 0
      l = 1
   10    dl = 1
         if (l .eq. n) go to 20
         if (a(l+1,l) .ne. 0.0d+0) dl = 2
   20    ll = l + dl - 1
         k = l
   30       km1 = k - 1
            dk = 1
            if (k .eq. n) go to 34
            if (a(k+1,k) .ne. 0.0d+0) dk = 2
   34       kk = k + dk - 1
            if (k .eq. l) go to 45
c
            do 40 i = k, kk
c
               do 40 j = l, ll
                dprec = 0.0d+0
                  do 35 ia = l, km1
                     dprec = dprec + a(ia,i) * c(ia,j)
   35             continue
                c(i,j) = c(i,j) - dprec
   40       continue
c
   45       if (dl .eq. 2) go to 60
            if (dk .eq. 2) go to 50
            t(1,1) = a(k,k) + a(l,l)
            if (t(1,1) .eq. 0.0d+0) go to 130
            c(k,l) = c(k,l) / t(1,1)
            go to 90
   50       t(1,1) = a(k,k) + a(l,l)
            t(1,2) = a(kk,k)
            t(2,1) = a(k,kk)
            t(2,2) = a(kk,kk) + a(l,l)
            p(1) = c(k,l)
            p(2) = c(kk,l)
            nsys = 2
            call dgefa(t,ldim,nsys,ipvt,info)
            if (info .ne. 0) go to 130
            call dgesl(t,ldim,nsys,ipvt,p,job)
            c(k,l) = p(1)
            c(kk,l) = p(2)
            go to 90
   60       if (dk .eq. 2) go to 70
            t(1,1) = a(k,k) + a(l,l)
            t(1,2) = a(ll,l)
            t(2,1) = a(l,ll)
            t(2,2) = a(k,k) + a(ll,ll)
            p(1) = c(k,l)
            p(2) = c(k,ll)
            nsys = 2
            call dgefa(t,ldim,nsys,ipvt,info)
            if (info .ne. 0) go to 130
            call dgesl(t,ldim,nsys,ipvt,p,job)
            c(k,l) = p(1)
            c(k,ll) = p(2)
            go to 90
   70       if (k .ne. l) go to 80
            t(1,1) = a(l,l)
            t(1,2) = a(ll,l)
            t(1,3) = 0.0d+0
            t(2,1) = a(l,ll)
            t(2,2) = a(l,l) + a(ll,ll)
            t(2,3) = t(1,2)
            t(3,1) = 0.0d+0
            t(3,2) = t(2,1)
            t(3,3) = a(ll,ll)
            p(1) = c(l,l) * 0.50d+0
            p(2) = c(ll,l)
            p(3) = c(ll,ll) * 0.50d+0
            nsys = 3
            call dgefa(t,ldim,nsys,ipvt,info)
            if (info .ne. 0) go to 130
            call dgesl(t,ldim,nsys,ipvt,p,job)
            c(l,l) = p(1)
            c(ll,l) = p(2)
            c(l,ll) = p(2)
            c(ll,ll) = p(3)
            go to 90
   80       t(1,1) = a(k,k) + a(l,l)
            t(1,2) = a(kk,k)
            t(1,3) = a(ll,l)
            t(1,4) = 0.0d+0
            t(2,1) = a(k,kk)
            t(2,2) = a(kk,kk) + a(l,l)
            t(2,3) = 0.0d+0
            t(2,4) = t(1,3)
            t(3,1) = a(l,ll)
            t(3,2) = 0.0d+0
            t(3,3) = a(k,k) + a(ll,ll)
            t(3,4) = t(1,2)
            t(4,1) = 0.0d+0
            t(4,2) = t(3,1)
            t(4,3) = t(2,1)
            t(4,4) = a(kk,kk) + a(ll,ll)
            p(1) = c(k,l)
            p(2) = c(kk,l)
            p(3) = c(k,ll)
            p(4) = c(kk,ll)
            nsys = 4
            call dgefa(t,ldim,nsys,ipvt,info)
            if (info .ne. 0) go to 130
            call dgesl(t,ldim,nsys,ipvt,p,job)
            c(k,l) = p(1)
            c(kk,l) = p(2)
            c(k,ll) = p(3)
            c(kk,ll) = p(4)
   90    k = k + dk
         if (k .le. n) go to 30
         ldl = l + dl
         if (ldl .gt. n) return
c
         do 120 j = ldl, n
c
            do 100 i = l, ll
               c(i,j) = c(j,i)
  100       continue
c
            do 120 i = j, n
                dprec = 0.0d+0
               do 110 k = l, ll
                dprec = dprec + c(i,k) * a(k,j)
                dprec = dprec + a(k,i) * c(k,j)
  110          continue
                c(i,j) = c(i,j) - dprec
               c(j,i) = c(i,j)
  120    continue
c
      l = ldl
      go to 10
c
  130 ierr = 1
      return
      end