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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:45