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


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