ztgsy2.c
Go to the documentation of this file.
00001 /* ztgsy2.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__2 = 2;
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int ztgsy2_(char *trans, integer *ijob, integer *m, integer *
00022         n, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, 
00023         doublecomplex *c__, integer *ldc, doublecomplex *d__, integer *ldd, 
00024         doublecomplex *e, integer *lde, doublecomplex *f, integer *ldf, 
00025         doublereal *scale, doublereal *rdsum, doublereal *rdscal, integer *
00026         info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1, 
00030             d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3, 
00031             i__4;
00032     doublecomplex z__1, z__2, z__3, z__4, z__5, z__6;
00033 
00034     /* Builtin functions */
00035     void d_cnjg(doublecomplex *, doublecomplex *);
00036 
00037     /* Local variables */
00038     integer i__, j, k;
00039     doublecomplex z__[4]        /* was [2][2] */, rhs[2];
00040     integer ierr, ipiv[2], jpiv[2];
00041     doublecomplex alpha;
00042     extern logical lsame_(char *, char *);
00043     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
00044             doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, 
00045             doublecomplex *, integer *, doublecomplex *, integer *), zgesc2_(
00046             integer *, doublecomplex *, integer *, doublecomplex *, integer *, 
00047              integer *, doublereal *), zgetc2_(integer *, doublecomplex *, 
00048             integer *, integer *, integer *, integer *);
00049     doublereal scaloc;
00050     extern /* Subroutine */ int xerbla_(char *, integer *), zlatdf_(
00051             integer *, integer *, doublecomplex *, integer *, doublecomplex *, 
00052              doublereal *, doublereal *, integer *, integer *);
00053     logical notran;
00054 
00055 
00056 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00057 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00058 /*     November 2006 */
00059 
00060 /*     .. Scalar Arguments .. */
00061 /*     .. */
00062 /*     .. Array Arguments .. */
00063 /*     .. */
00064 
00065 /*  Purpose */
00066 /*  ======= */
00067 
00068 /*  ZTGSY2 solves the generalized Sylvester equation */
00069 
00070 /*              A * R - L * B = scale *   C               (1) */
00071 /*              D * R - L * E = scale * F */
00072 
00073 /*  using Level 1 and 2 BLAS, where R and L are unknown M-by-N matrices, */
00074 /*  (A, D), (B, E) and (C, F) are given matrix pairs of size M-by-M, */
00075 /*  N-by-N and M-by-N, respectively. A, B, D and E are upper triangular */
00076 /*  (i.e., (A,D) and (B,E) in generalized Schur form). */
00077 
00078 /*  The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output */
00079 /*  scaling factor chosen to avoid overflow. */
00080 
00081 /*  In matrix notation solving equation (1) corresponds to solve */
00082 /*  Zx = scale * b, where Z is defined as */
00083 
00084 /*         Z = [ kron(In, A)  -kron(B', Im) ]             (2) */
00085 /*             [ kron(In, D)  -kron(E', Im) ], */
00086 
00087 /*  Ik is the identity matrix of size k and X' is the transpose of X. */
00088 /*  kron(X, Y) is the Kronecker product between the matrices X and Y. */
00089 
00090 /*  If TRANS = 'C', y in the conjugate transposed system Z'y = scale*b */
00091 /*  is solved for, which is equivalent to solve for R and L in */
00092 
00093 /*              A' * R  + D' * L   = scale *  C           (3) */
00094 /*              R  * B' + L  * E'  = scale * -F */
00095 
00096 /*  This case is used to compute an estimate of Dif[(A, D), (B, E)] = */
00097 /*  = sigma_min(Z) using reverse communicaton with ZLACON. */
00098 
00099 /*  ZTGSY2 also (IJOB >= 1) contributes to the computation in ZTGSYL */
00100 /*  of an upper bound on the separation between to matrix pairs. Then */
00101 /*  the input (A, D), (B, E) are sub-pencils of two matrix pairs in */
00102 /*  ZTGSYL. */
00103 
00104 /*  Arguments */
00105 /*  ========= */
00106 
00107 /*  TRANS   (input) CHARACTER*1 */
00108 /*          = 'N', solve the generalized Sylvester equation (1). */
00109 /*          = 'T': solve the 'transposed' system (3). */
00110 
00111 /*  IJOB    (input) INTEGER */
00112 /*          Specifies what kind of functionality to be performed. */
00113 /*          =0: solve (1) only. */
00114 /*          =1: A contribution from this subsystem to a Frobenius */
00115 /*              norm-based estimate of the separation between two matrix */
00116 /*              pairs is computed. (look ahead strategy is used). */
00117 /*          =2: A contribution from this subsystem to a Frobenius */
00118 /*              norm-based estimate of the separation between two matrix */
00119 /*              pairs is computed. (DGECON on sub-systems is used.) */
00120 /*          Not referenced if TRANS = 'T'. */
00121 
00122 /*  M       (input) INTEGER */
00123 /*          On entry, M specifies the order of A and D, and the row */
00124 /*          dimension of C, F, R and L. */
00125 
00126 /*  N       (input) INTEGER */
00127 /*          On entry, N specifies the order of B and E, and the column */
00128 /*          dimension of C, F, R and L. */
00129 
00130 /*  A       (input) COMPLEX*16 array, dimension (LDA, M) */
00131 /*          On entry, A contains an upper triangular matrix. */
00132 
00133 /*  LDA     (input) INTEGER */
00134 /*          The leading dimension of the matrix A. LDA >= max(1, M). */
00135 
00136 /*  B       (input) COMPLEX*16 array, dimension (LDB, N) */
00137 /*          On entry, B contains an upper triangular matrix. */
00138 
00139 /*  LDB     (input) INTEGER */
00140 /*          The leading dimension of the matrix B. LDB >= max(1, N). */
00141 
00142 /*  C       (input/output) COMPLEX*16 array, dimension (LDC, N) */
00143 /*          On entry, C contains the right-hand-side of the first matrix */
00144 /*          equation in (1). */
00145 /*          On exit, if IJOB = 0, C has been overwritten by the solution */
00146 /*          R. */
00147 
00148 /*  LDC     (input) INTEGER */
00149 /*          The leading dimension of the matrix C. LDC >= max(1, M). */
00150 
00151 /*  D       (input) COMPLEX*16 array, dimension (LDD, M) */
00152 /*          On entry, D contains an upper triangular matrix. */
00153 
00154 /*  LDD     (input) INTEGER */
00155 /*          The leading dimension of the matrix D. LDD >= max(1, M). */
00156 
00157 /*  E       (input) COMPLEX*16 array, dimension (LDE, N) */
00158 /*          On entry, E contains an upper triangular matrix. */
00159 
00160 /*  LDE     (input) INTEGER */
00161 /*          The leading dimension of the matrix E. LDE >= max(1, N). */
00162 
00163 /*  F       (input/output) COMPLEX*16 array, dimension (LDF, N) */
00164 /*          On entry, F contains the right-hand-side of the second matrix */
00165 /*          equation in (1). */
00166 /*          On exit, if IJOB = 0, F has been overwritten by the solution */
00167 /*          L. */
00168 
00169 /*  LDF     (input) INTEGER */
00170 /*          The leading dimension of the matrix F. LDF >= max(1, M). */
00171 
00172 /*  SCALE   (output) DOUBLE PRECISION */
00173 /*          On exit, 0 <= SCALE <= 1. If 0 < SCALE < 1, the solutions */
00174 /*          R and L (C and F on entry) will hold the solutions to a */
00175 /*          slightly perturbed system but the input matrices A, B, D and */
00176 /*          E have not been changed. If SCALE = 0, R and L will hold the */
00177 /*          solutions to the homogeneous system with C = F = 0. */
00178 /*          Normally, SCALE = 1. */
00179 
00180 /*  RDSUM   (input/output) DOUBLE PRECISION */
00181 /*          On entry, the sum of squares of computed contributions to */
00182 /*          the Dif-estimate under computation by ZTGSYL, where the */
00183 /*          scaling factor RDSCAL (see below) has been factored out. */
00184 /*          On exit, the corresponding sum of squares updated with the */
00185 /*          contributions from the current sub-system. */
00186 /*          If TRANS = 'T' RDSUM is not touched. */
00187 /*          NOTE: RDSUM only makes sense when ZTGSY2 is called by */
00188 /*          ZTGSYL. */
00189 
00190 /*  RDSCAL  (input/output) DOUBLE PRECISION */
00191 /*          On entry, scaling factor used to prevent overflow in RDSUM. */
00192 /*          On exit, RDSCAL is updated w.r.t. the current contributions */
00193 /*          in RDSUM. */
00194 /*          If TRANS = 'T', RDSCAL is not touched. */
00195 /*          NOTE: RDSCAL only makes sense when ZTGSY2 is called by */
00196 /*          ZTGSYL. */
00197 
00198 /*  INFO    (output) INTEGER */
00199 /*          On exit, if INFO is set to */
00200 /*            =0: Successful exit */
00201 /*            <0: If INFO = -i, input argument number i is illegal. */
00202 /*            >0: The matrix pairs (A, D) and (B, E) have common or very */
00203 /*                close eigenvalues. */
00204 
00205 /*  Further Details */
00206 /*  =============== */
00207 
00208 /*  Based on contributions by */
00209 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00210 /*     Umea University, S-901 87 Umea, Sweden. */
00211 
00212 /*  ===================================================================== */
00213 
00214 /*     .. Parameters .. */
00215 /*     .. */
00216 /*     .. Local Scalars .. */
00217 /*     .. */
00218 /*     .. Local Arrays .. */
00219 /*     .. */
00220 /*     .. External Functions .. */
00221 /*     .. */
00222 /*     .. External Subroutines .. */
00223 /*     .. */
00224 /*     .. Intrinsic Functions .. */
00225 /*     .. */
00226 /*     .. Executable Statements .. */
00227 
00228 /*     Decode and test input parameters */
00229 
00230     /* Parameter adjustments */
00231     a_dim1 = *lda;
00232     a_offset = 1 + a_dim1;
00233     a -= a_offset;
00234     b_dim1 = *ldb;
00235     b_offset = 1 + b_dim1;
00236     b -= b_offset;
00237     c_dim1 = *ldc;
00238     c_offset = 1 + c_dim1;
00239     c__ -= c_offset;
00240     d_dim1 = *ldd;
00241     d_offset = 1 + d_dim1;
00242     d__ -= d_offset;
00243     e_dim1 = *lde;
00244     e_offset = 1 + e_dim1;
00245     e -= e_offset;
00246     f_dim1 = *ldf;
00247     f_offset = 1 + f_dim1;
00248     f -= f_offset;
00249 
00250     /* Function Body */
00251     *info = 0;
00252     ierr = 0;
00253     notran = lsame_(trans, "N");
00254     if (! notran && ! lsame_(trans, "C")) {
00255         *info = -1;
00256     } else if (notran) {
00257         if (*ijob < 0 || *ijob > 2) {
00258             *info = -2;
00259         }
00260     }
00261     if (*info == 0) {
00262         if (*m <= 0) {
00263             *info = -3;
00264         } else if (*n <= 0) {
00265             *info = -4;
00266         } else if (*lda < max(1,*m)) {
00267             *info = -5;
00268         } else if (*ldb < max(1,*n)) {
00269             *info = -8;
00270         } else if (*ldc < max(1,*m)) {
00271             *info = -10;
00272         } else if (*ldd < max(1,*m)) {
00273             *info = -12;
00274         } else if (*lde < max(1,*n)) {
00275             *info = -14;
00276         } else if (*ldf < max(1,*m)) {
00277             *info = -16;
00278         }
00279     }
00280     if (*info != 0) {
00281         i__1 = -(*info);
00282         xerbla_("ZTGSY2", &i__1);
00283         return 0;
00284     }
00285 
00286     if (notran) {
00287 
00288 /*        Solve (I, J) - system */
00289 /*           A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
00290 /*           D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
00291 /*        for I = M, M - 1, ..., 1; J = 1, 2, ..., N */
00292 
00293         *scale = 1.;
00294         scaloc = 1.;
00295         i__1 = *n;
00296         for (j = 1; j <= i__1; ++j) {
00297             for (i__ = *m; i__ >= 1; --i__) {
00298 
00299 /*              Build 2 by 2 system */
00300 
00301                 i__2 = i__ + i__ * a_dim1;
00302                 z__[0].r = a[i__2].r, z__[0].i = a[i__2].i;
00303                 i__2 = i__ + i__ * d_dim1;
00304                 z__[1].r = d__[i__2].r, z__[1].i = d__[i__2].i;
00305                 i__2 = j + j * b_dim1;
00306                 z__1.r = -b[i__2].r, z__1.i = -b[i__2].i;
00307                 z__[2].r = z__1.r, z__[2].i = z__1.i;
00308                 i__2 = j + j * e_dim1;
00309                 z__1.r = -e[i__2].r, z__1.i = -e[i__2].i;
00310                 z__[3].r = z__1.r, z__[3].i = z__1.i;
00311 
00312 /*              Set up right hand side(s) */
00313 
00314                 i__2 = i__ + j * c_dim1;
00315                 rhs[0].r = c__[i__2].r, rhs[0].i = c__[i__2].i;
00316                 i__2 = i__ + j * f_dim1;
00317                 rhs[1].r = f[i__2].r, rhs[1].i = f[i__2].i;
00318 
00319 /*              Solve Z * x = RHS */
00320 
00321                 zgetc2_(&c__2, z__, &c__2, ipiv, jpiv, &ierr);
00322                 if (ierr > 0) {
00323                     *info = ierr;
00324                 }
00325                 if (*ijob == 0) {
00326                     zgesc2_(&c__2, z__, &c__2, rhs, ipiv, jpiv, &scaloc);
00327                     if (scaloc != 1.) {
00328                         i__2 = *n;
00329                         for (k = 1; k <= i__2; ++k) {
00330                             z__1.r = scaloc, z__1.i = 0.;
00331                             zscal_(m, &z__1, &c__[k * c_dim1 + 1], &c__1);
00332                             z__1.r = scaloc, z__1.i = 0.;
00333                             zscal_(m, &z__1, &f[k * f_dim1 + 1], &c__1);
00334 /* L10: */
00335                         }
00336                         *scale *= scaloc;
00337                     }
00338                 } else {
00339                     zlatdf_(ijob, &c__2, z__, &c__2, rhs, rdsum, rdscal, ipiv, 
00340                              jpiv);
00341                 }
00342 
00343 /*              Unpack solution vector(s) */
00344 
00345                 i__2 = i__ + j * c_dim1;
00346                 c__[i__2].r = rhs[0].r, c__[i__2].i = rhs[0].i;
00347                 i__2 = i__ + j * f_dim1;
00348                 f[i__2].r = rhs[1].r, f[i__2].i = rhs[1].i;
00349 
00350 /*              Substitute R(I, J) and L(I, J) into remaining equation. */
00351 
00352                 if (i__ > 1) {
00353                     z__1.r = -rhs[0].r, z__1.i = -rhs[0].i;
00354                     alpha.r = z__1.r, alpha.i = z__1.i;
00355                     i__2 = i__ - 1;
00356                     zaxpy_(&i__2, &alpha, &a[i__ * a_dim1 + 1], &c__1, &c__[j 
00357                             * c_dim1 + 1], &c__1);
00358                     i__2 = i__ - 1;
00359                     zaxpy_(&i__2, &alpha, &d__[i__ * d_dim1 + 1], &c__1, &f[j 
00360                             * f_dim1 + 1], &c__1);
00361                 }
00362                 if (j < *n) {
00363                     i__2 = *n - j;
00364                     zaxpy_(&i__2, &rhs[1], &b[j + (j + 1) * b_dim1], ldb, &
00365                             c__[i__ + (j + 1) * c_dim1], ldc);
00366                     i__2 = *n - j;
00367                     zaxpy_(&i__2, &rhs[1], &e[j + (j + 1) * e_dim1], lde, &f[
00368                             i__ + (j + 1) * f_dim1], ldf);
00369                 }
00370 
00371 /* L20: */
00372             }
00373 /* L30: */
00374         }
00375     } else {
00376 
00377 /*        Solve transposed (I, J) - system: */
00378 /*           A(I, I)' * R(I, J) + D(I, I)' * L(J, J) = C(I, J) */
00379 /*           R(I, I) * B(J, J) + L(I, J) * E(J, J)   = -F(I, J) */
00380 /*        for I = 1, 2, ..., M, J = N, N - 1, ..., 1 */
00381 
00382         *scale = 1.;
00383         scaloc = 1.;
00384         i__1 = *m;
00385         for (i__ = 1; i__ <= i__1; ++i__) {
00386             for (j = *n; j >= 1; --j) {
00387 
00388 /*              Build 2 by 2 system Z' */
00389 
00390                 d_cnjg(&z__1, &a[i__ + i__ * a_dim1]);
00391                 z__[0].r = z__1.r, z__[0].i = z__1.i;
00392                 d_cnjg(&z__2, &b[j + j * b_dim1]);
00393                 z__1.r = -z__2.r, z__1.i = -z__2.i;
00394                 z__[1].r = z__1.r, z__[1].i = z__1.i;
00395                 d_cnjg(&z__1, &d__[i__ + i__ * d_dim1]);
00396                 z__[2].r = z__1.r, z__[2].i = z__1.i;
00397                 d_cnjg(&z__2, &e[j + j * e_dim1]);
00398                 z__1.r = -z__2.r, z__1.i = -z__2.i;
00399                 z__[3].r = z__1.r, z__[3].i = z__1.i;
00400 
00401 
00402 /*              Set up right hand side(s) */
00403 
00404                 i__2 = i__ + j * c_dim1;
00405                 rhs[0].r = c__[i__2].r, rhs[0].i = c__[i__2].i;
00406                 i__2 = i__ + j * f_dim1;
00407                 rhs[1].r = f[i__2].r, rhs[1].i = f[i__2].i;
00408 
00409 /*              Solve Z' * x = RHS */
00410 
00411                 zgetc2_(&c__2, z__, &c__2, ipiv, jpiv, &ierr);
00412                 if (ierr > 0) {
00413                     *info = ierr;
00414                 }
00415                 zgesc2_(&c__2, z__, &c__2, rhs, ipiv, jpiv, &scaloc);
00416                 if (scaloc != 1.) {
00417                     i__2 = *n;
00418                     for (k = 1; k <= i__2; ++k) {
00419                         z__1.r = scaloc, z__1.i = 0.;
00420                         zscal_(m, &z__1, &c__[k * c_dim1 + 1], &c__1);
00421                         z__1.r = scaloc, z__1.i = 0.;
00422                         zscal_(m, &z__1, &f[k * f_dim1 + 1], &c__1);
00423 /* L40: */
00424                     }
00425                     *scale *= scaloc;
00426                 }
00427 
00428 /*              Unpack solution vector(s) */
00429 
00430                 i__2 = i__ + j * c_dim1;
00431                 c__[i__2].r = rhs[0].r, c__[i__2].i = rhs[0].i;
00432                 i__2 = i__ + j * f_dim1;
00433                 f[i__2].r = rhs[1].r, f[i__2].i = rhs[1].i;
00434 
00435 /*              Substitute R(I, J) and L(I, J) into remaining equation. */
00436 
00437                 i__2 = j - 1;
00438                 for (k = 1; k <= i__2; ++k) {
00439                     i__3 = i__ + k * f_dim1;
00440                     i__4 = i__ + k * f_dim1;
00441                     d_cnjg(&z__4, &b[k + j * b_dim1]);
00442                     z__3.r = rhs[0].r * z__4.r - rhs[0].i * z__4.i, z__3.i = 
00443                             rhs[0].r * z__4.i + rhs[0].i * z__4.r;
00444                     z__2.r = f[i__4].r + z__3.r, z__2.i = f[i__4].i + z__3.i;
00445                     d_cnjg(&z__6, &e[k + j * e_dim1]);
00446                     z__5.r = rhs[1].r * z__6.r - rhs[1].i * z__6.i, z__5.i = 
00447                             rhs[1].r * z__6.i + rhs[1].i * z__6.r;
00448                     z__1.r = z__2.r + z__5.r, z__1.i = z__2.i + z__5.i;
00449                     f[i__3].r = z__1.r, f[i__3].i = z__1.i;
00450 /* L50: */
00451                 }
00452                 i__2 = *m;
00453                 for (k = i__ + 1; k <= i__2; ++k) {
00454                     i__3 = k + j * c_dim1;
00455                     i__4 = k + j * c_dim1;
00456                     d_cnjg(&z__4, &a[i__ + k * a_dim1]);
00457                     z__3.r = z__4.r * rhs[0].r - z__4.i * rhs[0].i, z__3.i = 
00458                             z__4.r * rhs[0].i + z__4.i * rhs[0].r;
00459                     z__2.r = c__[i__4].r - z__3.r, z__2.i = c__[i__4].i - 
00460                             z__3.i;
00461                     d_cnjg(&z__6, &d__[i__ + k * d_dim1]);
00462                     z__5.r = z__6.r * rhs[1].r - z__6.i * rhs[1].i, z__5.i = 
00463                             z__6.r * rhs[1].i + z__6.i * rhs[1].r;
00464                     z__1.r = z__2.r - z__5.r, z__1.i = z__2.i - z__5.i;
00465                     c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
00466 /* L60: */
00467                 }
00468 
00469 /* L70: */
00470             }
00471 /* L80: */
00472         }
00473     }
00474     return 0;
00475 
00476 /*     End of ZTGSY2 */
00477 
00478 } /* ztgsy2_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43