zgtsv.c
Go to the documentation of this file.
00001 /* zgtsv.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 /* Subroutine */ int zgtsv_(integer *n, integer *nrhs, doublecomplex *dl, 
00017         doublecomplex *d__, doublecomplex *du, doublecomplex *b, integer *ldb, 
00018          integer *info)
00019 {
00020     /* System generated locals */
00021     integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7;
00022     doublereal d__1, d__2, d__3, d__4;
00023     doublecomplex z__1, z__2, z__3, z__4, z__5;
00024 
00025     /* Builtin functions */
00026     double d_imag(doublecomplex *);
00027     void z_div(doublecomplex *, doublecomplex *, doublecomplex *);
00028 
00029     /* Local variables */
00030     integer j, k;
00031     doublecomplex temp, mult;
00032     extern /* Subroutine */ int xerbla_(char *, integer *);
00033 
00034 
00035 /*  -- LAPACK routine (version 3.2) -- */
00036 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00037 /*     November 2006 */
00038 
00039 /*     .. Scalar Arguments .. */
00040 /*     .. */
00041 /*     .. Array Arguments .. */
00042 /*     .. */
00043 
00044 /*  Purpose */
00045 /*  ======= */
00046 
00047 /*  ZGTSV  solves the equation */
00048 
00049 /*     A*X = B, */
00050 
00051 /*  where A is an N-by-N tridiagonal matrix, by Gaussian elimination with */
00052 /*  partial pivoting. */
00053 
00054 /*  Note that the equation  A'*X = B  may be solved by interchanging the */
00055 /*  order of the arguments DU and DL. */
00056 
00057 /*  Arguments */
00058 /*  ========= */
00059 
00060 /*  N       (input) INTEGER */
00061 /*          The order of the matrix A.  N >= 0. */
00062 
00063 /*  NRHS    (input) INTEGER */
00064 /*          The number of right hand sides, i.e., the number of columns */
00065 /*          of the matrix B.  NRHS >= 0. */
00066 
00067 /*  DL      (input/output) COMPLEX*16 array, dimension (N-1) */
00068 /*          On entry, DL must contain the (n-1) subdiagonal elements of */
00069 /*          A. */
00070 /*          On exit, DL is overwritten by the (n-2) elements of the */
00071 /*          second superdiagonal of the upper triangular matrix U from */
00072 /*          the LU factorization of A, in DL(1), ..., DL(n-2). */
00073 
00074 /*  D       (input/output) COMPLEX*16 array, dimension (N) */
00075 /*          On entry, D must contain the diagonal elements of A. */
00076 /*          On exit, D is overwritten by the n diagonal elements of U. */
00077 
00078 /*  DU      (input/output) COMPLEX*16 array, dimension (N-1) */
00079 /*          On entry, DU must contain the (n-1) superdiagonal elements */
00080 /*          of A. */
00081 /*          On exit, DU is overwritten by the (n-1) elements of the first */
00082 /*          superdiagonal of U. */
00083 
00084 /*  B       (input/output) COMPLEX*16 array, dimension (LDB,NRHS) */
00085 /*          On entry, the N-by-NRHS right hand side matrix B. */
00086 /*          On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
00087 
00088 /*  LDB     (input) INTEGER */
00089 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00090 
00091 /*  INFO    (output) INTEGER */
00092 /*          = 0:  successful exit */
00093 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00094 /*          > 0:  if INFO = i, U(i,i) is exactly zero, and the solution */
00095 /*                has not been computed.  The factorization has not been */
00096 /*                completed unless i = N. */
00097 
00098 /*  ===================================================================== */
00099 
00100 /*     .. Parameters .. */
00101 /*     .. */
00102 /*     .. Local Scalars .. */
00103 /*     .. */
00104 /*     .. Intrinsic Functions .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. Statement Functions .. */
00109 /*     .. */
00110 /*     .. Statement Function definitions .. */
00111 /*     .. */
00112 /*     .. Executable Statements .. */
00113 
00114     /* Parameter adjustments */
00115     --dl;
00116     --d__;
00117     --du;
00118     b_dim1 = *ldb;
00119     b_offset = 1 + b_dim1;
00120     b -= b_offset;
00121 
00122     /* Function Body */
00123     *info = 0;
00124     if (*n < 0) {
00125         *info = -1;
00126     } else if (*nrhs < 0) {
00127         *info = -2;
00128     } else if (*ldb < max(1,*n)) {
00129         *info = -7;
00130     }
00131     if (*info != 0) {
00132         i__1 = -(*info);
00133         xerbla_("ZGTSV ", &i__1);
00134         return 0;
00135     }
00136 
00137     if (*n == 0) {
00138         return 0;
00139     }
00140 
00141     i__1 = *n - 1;
00142     for (k = 1; k <= i__1; ++k) {
00143         i__2 = k;
00144         if (dl[i__2].r == 0. && dl[i__2].i == 0.) {
00145 
00146 /*           Subdiagonal is zero, no elimination is required. */
00147 
00148             i__2 = k;
00149             if (d__[i__2].r == 0. && d__[i__2].i == 0.) {
00150 
00151 /*              Diagonal is zero: set INFO = K and return; a unique */
00152 /*              solution can not be found. */
00153 
00154                 *info = k;
00155                 return 0;
00156             }
00157         } else /* if(complicated condition) */ {
00158             i__2 = k;
00159             i__3 = k;
00160             if ((d__1 = d__[i__2].r, abs(d__1)) + (d__2 = d_imag(&d__[k]), 
00161                     abs(d__2)) >= (d__3 = dl[i__3].r, abs(d__3)) + (d__4 = 
00162                     d_imag(&dl[k]), abs(d__4))) {
00163 
00164 /*           No row interchange required */
00165 
00166                 z_div(&z__1, &dl[k], &d__[k]);
00167                 mult.r = z__1.r, mult.i = z__1.i;
00168                 i__2 = k + 1;
00169                 i__3 = k + 1;
00170                 i__4 = k;
00171                 z__2.r = mult.r * du[i__4].r - mult.i * du[i__4].i, z__2.i = 
00172                         mult.r * du[i__4].i + mult.i * du[i__4].r;
00173                 z__1.r = d__[i__3].r - z__2.r, z__1.i = d__[i__3].i - z__2.i;
00174                 d__[i__2].r = z__1.r, d__[i__2].i = z__1.i;
00175                 i__2 = *nrhs;
00176                 for (j = 1; j <= i__2; ++j) {
00177                     i__3 = k + 1 + j * b_dim1;
00178                     i__4 = k + 1 + j * b_dim1;
00179                     i__5 = k + j * b_dim1;
00180                     z__2.r = mult.r * b[i__5].r - mult.i * b[i__5].i, z__2.i =
00181                              mult.r * b[i__5].i + mult.i * b[i__5].r;
00182                     z__1.r = b[i__4].r - z__2.r, z__1.i = b[i__4].i - z__2.i;
00183                     b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00184 /* L10: */
00185                 }
00186                 if (k < *n - 1) {
00187                     i__2 = k;
00188                     dl[i__2].r = 0., dl[i__2].i = 0.;
00189                 }
00190             } else {
00191 
00192 /*           Interchange rows K and K+1 */
00193 
00194                 z_div(&z__1, &d__[k], &dl[k]);
00195                 mult.r = z__1.r, mult.i = z__1.i;
00196                 i__2 = k;
00197                 i__3 = k;
00198                 d__[i__2].r = dl[i__3].r, d__[i__2].i = dl[i__3].i;
00199                 i__2 = k + 1;
00200                 temp.r = d__[i__2].r, temp.i = d__[i__2].i;
00201                 i__2 = k + 1;
00202                 i__3 = k;
00203                 z__2.r = mult.r * temp.r - mult.i * temp.i, z__2.i = mult.r * 
00204                         temp.i + mult.i * temp.r;
00205                 z__1.r = du[i__3].r - z__2.r, z__1.i = du[i__3].i - z__2.i;
00206                 d__[i__2].r = z__1.r, d__[i__2].i = z__1.i;
00207                 if (k < *n - 1) {
00208                     i__2 = k;
00209                     i__3 = k + 1;
00210                     dl[i__2].r = du[i__3].r, dl[i__2].i = du[i__3].i;
00211                     i__2 = k + 1;
00212                     z__2.r = -mult.r, z__2.i = -mult.i;
00213                     i__3 = k;
00214                     z__1.r = z__2.r * dl[i__3].r - z__2.i * dl[i__3].i, 
00215                             z__1.i = z__2.r * dl[i__3].i + z__2.i * dl[i__3]
00216                             .r;
00217                     du[i__2].r = z__1.r, du[i__2].i = z__1.i;
00218                 }
00219                 i__2 = k;
00220                 du[i__2].r = temp.r, du[i__2].i = temp.i;
00221                 i__2 = *nrhs;
00222                 for (j = 1; j <= i__2; ++j) {
00223                     i__3 = k + j * b_dim1;
00224                     temp.r = b[i__3].r, temp.i = b[i__3].i;
00225                     i__3 = k + j * b_dim1;
00226                     i__4 = k + 1 + j * b_dim1;
00227                     b[i__3].r = b[i__4].r, b[i__3].i = b[i__4].i;
00228                     i__3 = k + 1 + j * b_dim1;
00229                     i__4 = k + 1 + j * b_dim1;
00230                     z__2.r = mult.r * b[i__4].r - mult.i * b[i__4].i, z__2.i =
00231                              mult.r * b[i__4].i + mult.i * b[i__4].r;
00232                     z__1.r = temp.r - z__2.r, z__1.i = temp.i - z__2.i;
00233                     b[i__3].r = z__1.r, b[i__3].i = z__1.i;
00234 /* L20: */
00235                 }
00236             }
00237         }
00238 /* L30: */
00239     }
00240     i__1 = *n;
00241     if (d__[i__1].r == 0. && d__[i__1].i == 0.) {
00242         *info = *n;
00243         return 0;
00244     }
00245 
00246 /*     Back solve with the matrix U from the factorization. */
00247 
00248     i__1 = *nrhs;
00249     for (j = 1; j <= i__1; ++j) {
00250         i__2 = *n + j * b_dim1;
00251         z_div(&z__1, &b[*n + j * b_dim1], &d__[*n]);
00252         b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00253         if (*n > 1) {
00254             i__2 = *n - 1 + j * b_dim1;
00255             i__3 = *n - 1 + j * b_dim1;
00256             i__4 = *n - 1;
00257             i__5 = *n + j * b_dim1;
00258             z__3.r = du[i__4].r * b[i__5].r - du[i__4].i * b[i__5].i, z__3.i =
00259                      du[i__4].r * b[i__5].i + du[i__4].i * b[i__5].r;
00260             z__2.r = b[i__3].r - z__3.r, z__2.i = b[i__3].i - z__3.i;
00261             z_div(&z__1, &z__2, &d__[*n - 1]);
00262             b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00263         }
00264         for (k = *n - 2; k >= 1; --k) {
00265             i__2 = k + j * b_dim1;
00266             i__3 = k + j * b_dim1;
00267             i__4 = k;
00268             i__5 = k + 1 + j * b_dim1;
00269             z__4.r = du[i__4].r * b[i__5].r - du[i__4].i * b[i__5].i, z__4.i =
00270                      du[i__4].r * b[i__5].i + du[i__4].i * b[i__5].r;
00271             z__3.r = b[i__3].r - z__4.r, z__3.i = b[i__3].i - z__4.i;
00272             i__6 = k;
00273             i__7 = k + 2 + j * b_dim1;
00274             z__5.r = dl[i__6].r * b[i__7].r - dl[i__6].i * b[i__7].i, z__5.i =
00275                      dl[i__6].r * b[i__7].i + dl[i__6].i * b[i__7].r;
00276             z__2.r = z__3.r - z__5.r, z__2.i = z__3.i - z__5.i;
00277             z_div(&z__1, &z__2, &d__[k]);
00278             b[i__2].r = z__1.r, b[i__2].i = z__1.i;
00279 /* L40: */
00280         }
00281 /* L50: */
00282     }
00283 
00284     return 0;
00285 
00286 /*     End of ZGTSV */
00287 
00288 } /* zgtsv_ */


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