slagts.c
Go to the documentation of this file.
00001 /* slagts.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 slagts_(integer *job, integer *n, real *a, real *b, real 
00017         *c__, real *d__, integer *in, real *y, real *tol, integer *info)
00018 {
00019     /* System generated locals */
00020     integer i__1;
00021     real r__1, r__2, r__3, r__4, r__5;
00022 
00023     /* Builtin functions */
00024     double r_sign(real *, real *);
00025 
00026     /* Local variables */
00027     integer k;
00028     real ak, eps, temp, pert, absak, sfmin;
00029     extern doublereal slamch_(char *);
00030     extern /* Subroutine */ int xerbla_(char *, integer *);
00031     real bignum;
00032 
00033 
00034 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00035 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00036 /*     November 2006 */
00037 
00038 /*     .. Scalar Arguments .. */
00039 /*     .. */
00040 /*     .. Array Arguments .. */
00041 /*     .. */
00042 
00043 /*  Purpose */
00044 /*  ======= */
00045 
00046 /*  SLAGTS may be used to solve one of the systems of equations */
00047 
00048 /*     (T - lambda*I)*x = y   or   (T - lambda*I)'*x = y, */
00049 
00050 /*  where T is an n by n tridiagonal matrix, for x, following the */
00051 /*  factorization of (T - lambda*I) as */
00052 
00053 /*     (T - lambda*I) = P*L*U , */
00054 
00055 /*  by routine SLAGTF. The choice of equation to be solved is */
00056 /*  controlled by the argument JOB, and in each case there is an option */
00057 /*  to perturb zero or very small diagonal elements of U, this option */
00058 /*  being intended for use in applications such as inverse iteration. */
00059 
00060 /*  Arguments */
00061 /*  ========= */
00062 
00063 /*  JOB     (input) INTEGER */
00064 /*          Specifies the job to be performed by SLAGTS as follows: */
00065 /*          =  1: The equations  (T - lambda*I)x = y  are to be solved, */
00066 /*                but diagonal elements of U are not to be perturbed. */
00067 /*          = -1: The equations  (T - lambda*I)x = y  are to be solved */
00068 /*                and, if overflow would otherwise occur, the diagonal */
00069 /*                elements of U are to be perturbed. See argument TOL */
00070 /*                below. */
00071 /*          =  2: The equations  (T - lambda*I)'x = y  are to be solved, */
00072 /*                but diagonal elements of U are not to be perturbed. */
00073 /*          = -2: The equations  (T - lambda*I)'x = y  are to be solved */
00074 /*                and, if overflow would otherwise occur, the diagonal */
00075 /*                elements of U are to be perturbed. See argument TOL */
00076 /*                below. */
00077 
00078 /*  N       (input) INTEGER */
00079 /*          The order of the matrix T. */
00080 
00081 /*  A       (input) REAL array, dimension (N) */
00082 /*          On entry, A must contain the diagonal elements of U as */
00083 /*          returned from SLAGTF. */
00084 
00085 /*  B       (input) REAL array, dimension (N-1) */
00086 /*          On entry, B must contain the first super-diagonal elements of */
00087 /*          U as returned from SLAGTF. */
00088 
00089 /*  C       (input) REAL array, dimension (N-1) */
00090 /*          On entry, C must contain the sub-diagonal elements of L as */
00091 /*          returned from SLAGTF. */
00092 
00093 /*  D       (input) REAL array, dimension (N-2) */
00094 /*          On entry, D must contain the second super-diagonal elements */
00095 /*          of U as returned from SLAGTF. */
00096 
00097 /*  IN      (input) INTEGER array, dimension (N) */
00098 /*          On entry, IN must contain details of the matrix P as returned */
00099 /*          from SLAGTF. */
00100 
00101 /*  Y       (input/output) REAL array, dimension (N) */
00102 /*          On entry, the right hand side vector y. */
00103 /*          On exit, Y is overwritten by the solution vector x. */
00104 
00105 /*  TOL     (input/output) REAL */
00106 /*          On entry, with  JOB .lt. 0, TOL should be the minimum */
00107 /*          perturbation to be made to very small diagonal elements of U. */
00108 /*          TOL should normally be chosen as about eps*norm(U), where eps */
00109 /*          is the relative machine precision, but if TOL is supplied as */
00110 /*          non-positive, then it is reset to eps*max( abs( u(i,j) ) ). */
00111 /*          If  JOB .gt. 0  then TOL is not referenced. */
00112 
00113 /*          On exit, TOL is changed as described above, only if TOL is */
00114 /*          non-positive on entry. Otherwise TOL is unchanged. */
00115 
00116 /*  INFO    (output) INTEGER */
00117 /*          = 0   : successful exit */
00118 /*          .lt. 0: if INFO = -i, the i-th argument had an illegal value */
00119 /*          .gt. 0: overflow would occur when computing the INFO(th) */
00120 /*                  element of the solution vector x. This can only occur */
00121 /*                  when JOB is supplied as positive and either means */
00122 /*                  that a diagonal element of U is very small, or that */
00123 /*                  the elements of the right-hand side vector y are very */
00124 /*                  large. */
00125 
00126 /*  ===================================================================== */
00127 
00128 /*     .. Parameters .. */
00129 /*     .. */
00130 /*     .. Local Scalars .. */
00131 /*     .. */
00132 /*     .. Intrinsic Functions .. */
00133 /*     .. */
00134 /*     .. External Functions .. */
00135 /*     .. */
00136 /*     .. External Subroutines .. */
00137 /*     .. */
00138 /*     .. Executable Statements .. */
00139 
00140     /* Parameter adjustments */
00141     --y;
00142     --in;
00143     --d__;
00144     --c__;
00145     --b;
00146     --a;
00147 
00148     /* Function Body */
00149     *info = 0;
00150     if (abs(*job) > 2 || *job == 0) {
00151         *info = -1;
00152     } else if (*n < 0) {
00153         *info = -2;
00154     }
00155     if (*info != 0) {
00156         i__1 = -(*info);
00157         xerbla_("SLAGTS", &i__1);
00158         return 0;
00159     }
00160 
00161     if (*n == 0) {
00162         return 0;
00163     }
00164 
00165     eps = slamch_("Epsilon");
00166     sfmin = slamch_("Safe minimum");
00167     bignum = 1.f / sfmin;
00168 
00169     if (*job < 0) {
00170         if (*tol <= 0.f) {
00171             *tol = dabs(a[1]);
00172             if (*n > 1) {
00173 /* Computing MAX */
00174                 r__1 = *tol, r__2 = dabs(a[2]), r__1 = max(r__1,r__2), r__2 = 
00175                         dabs(b[1]);
00176                 *tol = dmax(r__1,r__2);
00177             }
00178             i__1 = *n;
00179             for (k = 3; k <= i__1; ++k) {
00180 /* Computing MAX */
00181                 r__4 = *tol, r__5 = (r__1 = a[k], dabs(r__1)), r__4 = max(
00182                         r__4,r__5), r__5 = (r__2 = b[k - 1], dabs(r__2)), 
00183                         r__4 = max(r__4,r__5), r__5 = (r__3 = d__[k - 2], 
00184                         dabs(r__3));
00185                 *tol = dmax(r__4,r__5);
00186 /* L10: */
00187             }
00188             *tol *= eps;
00189             if (*tol == 0.f) {
00190                 *tol = eps;
00191             }
00192         }
00193     }
00194 
00195     if (abs(*job) == 1) {
00196         i__1 = *n;
00197         for (k = 2; k <= i__1; ++k) {
00198             if (in[k - 1] == 0) {
00199                 y[k] -= c__[k - 1] * y[k - 1];
00200             } else {
00201                 temp = y[k - 1];
00202                 y[k - 1] = y[k];
00203                 y[k] = temp - c__[k - 1] * y[k];
00204             }
00205 /* L20: */
00206         }
00207         if (*job == 1) {
00208             for (k = *n; k >= 1; --k) {
00209                 if (k <= *n - 2) {
00210                     temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
00211                 } else if (k == *n - 1) {
00212                     temp = y[k] - b[k] * y[k + 1];
00213                 } else {
00214                     temp = y[k];
00215                 }
00216                 ak = a[k];
00217                 absak = dabs(ak);
00218                 if (absak < 1.f) {
00219                     if (absak < sfmin) {
00220                         if (absak == 0.f || dabs(temp) * sfmin > absak) {
00221                             *info = k;
00222                             return 0;
00223                         } else {
00224                             temp *= bignum;
00225                             ak *= bignum;
00226                         }
00227                     } else if (dabs(temp) > absak * bignum) {
00228                         *info = k;
00229                         return 0;
00230                     }
00231                 }
00232                 y[k] = temp / ak;
00233 /* L30: */
00234             }
00235         } else {
00236             for (k = *n; k >= 1; --k) {
00237                 if (k <= *n - 2) {
00238                     temp = y[k] - b[k] * y[k + 1] - d__[k] * y[k + 2];
00239                 } else if (k == *n - 1) {
00240                     temp = y[k] - b[k] * y[k + 1];
00241                 } else {
00242                     temp = y[k];
00243                 }
00244                 ak = a[k];
00245                 pert = r_sign(tol, &ak);
00246 L40:
00247                 absak = dabs(ak);
00248                 if (absak < 1.f) {
00249                     if (absak < sfmin) {
00250                         if (absak == 0.f || dabs(temp) * sfmin > absak) {
00251                             ak += pert;
00252                             pert *= 2;
00253                             goto L40;
00254                         } else {
00255                             temp *= bignum;
00256                             ak *= bignum;
00257                         }
00258                     } else if (dabs(temp) > absak * bignum) {
00259                         ak += pert;
00260                         pert *= 2;
00261                         goto L40;
00262                     }
00263                 }
00264                 y[k] = temp / ak;
00265 /* L50: */
00266             }
00267         }
00268     } else {
00269 
00270 /*        Come to here if  JOB = 2 or -2 */
00271 
00272         if (*job == 2) {
00273             i__1 = *n;
00274             for (k = 1; k <= i__1; ++k) {
00275                 if (k >= 3) {
00276                     temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
00277                 } else if (k == 2) {
00278                     temp = y[k] - b[k - 1] * y[k - 1];
00279                 } else {
00280                     temp = y[k];
00281                 }
00282                 ak = a[k];
00283                 absak = dabs(ak);
00284                 if (absak < 1.f) {
00285                     if (absak < sfmin) {
00286                         if (absak == 0.f || dabs(temp) * sfmin > absak) {
00287                             *info = k;
00288                             return 0;
00289                         } else {
00290                             temp *= bignum;
00291                             ak *= bignum;
00292                         }
00293                     } else if (dabs(temp) > absak * bignum) {
00294                         *info = k;
00295                         return 0;
00296                     }
00297                 }
00298                 y[k] = temp / ak;
00299 /* L60: */
00300             }
00301         } else {
00302             i__1 = *n;
00303             for (k = 1; k <= i__1; ++k) {
00304                 if (k >= 3) {
00305                     temp = y[k] - b[k - 1] * y[k - 1] - d__[k - 2] * y[k - 2];
00306                 } else if (k == 2) {
00307                     temp = y[k] - b[k - 1] * y[k - 1];
00308                 } else {
00309                     temp = y[k];
00310                 }
00311                 ak = a[k];
00312                 pert = r_sign(tol, &ak);
00313 L70:
00314                 absak = dabs(ak);
00315                 if (absak < 1.f) {
00316                     if (absak < sfmin) {
00317                         if (absak == 0.f || dabs(temp) * sfmin > absak) {
00318                             ak += pert;
00319                             pert *= 2;
00320                             goto L70;
00321                         } else {
00322                             temp *= bignum;
00323                             ak *= bignum;
00324                         }
00325                     } else if (dabs(temp) > absak * bignum) {
00326                         ak += pert;
00327                         pert *= 2;
00328                         goto L70;
00329                     }
00330                 }
00331                 y[k] = temp / ak;
00332 /* L80: */
00333             }
00334         }
00335 
00336         for (k = *n; k >= 2; --k) {
00337             if (in[k - 1] == 0) {
00338                 y[k - 1] -= c__[k - 1] * y[k];
00339             } else {
00340                 temp = y[k - 1];
00341                 y[k - 1] = y[k];
00342                 y[k] = temp - c__[k - 1] * y[k];
00343             }
00344 /* L90: */
00345         }
00346     }
00347 
00348 /*     End of SLAGTS */
00349 
00350     return 0;
00351 } /* slagts_ */


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