dlagts.c
Go to the documentation of this file.
00001 /* dlagts.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 dlagts_(integer *job, integer *n, doublereal *a, 
00017         doublereal *b, doublereal *c__, doublereal *d__, integer *in, 
00018         doublereal *y, doublereal *tol, integer *info)
00019 {
00020     /* System generated locals */
00021     integer i__1;
00022     doublereal d__1, d__2, d__3, d__4, d__5;
00023 
00024     /* Builtin functions */
00025     double d_sign(doublereal *, doublereal *);
00026 
00027     /* Local variables */
00028     integer k;
00029     doublereal ak, eps, temp, pert, absak, sfmin;
00030     extern doublereal dlamch_(char *);
00031     extern /* Subroutine */ int xerbla_(char *, integer *);
00032     doublereal bignum;
00033 
00034 
00035 /*  -- LAPACK auxiliary 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 /*  DLAGTS may be used to solve one of the systems of equations */
00048 
00049 /*     (T - lambda*I)*x = y   or   (T - lambda*I)'*x = y, */
00050 
00051 /*  where T is an n by n tridiagonal matrix, for x, following the */
00052 /*  factorization of (T - lambda*I) as */
00053 
00054 /*     (T - lambda*I) = P*L*U , */
00055 
00056 /*  by routine DLAGTF. The choice of equation to be solved is */
00057 /*  controlled by the argument JOB, and in each case there is an option */
00058 /*  to perturb zero or very small diagonal elements of U, this option */
00059 /*  being intended for use in applications such as inverse iteration. */
00060 
00061 /*  Arguments */
00062 /*  ========= */
00063 
00064 /*  JOB     (input) INTEGER */
00065 /*          Specifies the job to be performed by DLAGTS as follows: */
00066 /*          =  1: The equations  (T - lambda*I)x = y  are to be solved, */
00067 /*                but diagonal elements of U are not to be perturbed. */
00068 /*          = -1: The equations  (T - lambda*I)x = y  are to be solved */
00069 /*                and, if overflow would otherwise occur, the diagonal */
00070 /*                elements of U are to be perturbed. See argument TOL */
00071 /*                below. */
00072 /*          =  2: The equations  (T - lambda*I)'x = y  are to be solved, */
00073 /*                but diagonal elements of U are not to be perturbed. */
00074 /*          = -2: The equations  (T - lambda*I)'x = y  are to be solved */
00075 /*                and, if overflow would otherwise occur, the diagonal */
00076 /*                elements of U are to be perturbed. See argument TOL */
00077 /*                below. */
00078 
00079 /*  N       (input) INTEGER */
00080 /*          The order of the matrix T. */
00081 
00082 /*  A       (input) DOUBLE PRECISION array, dimension (N) */
00083 /*          On entry, A must contain the diagonal elements of U as */
00084 /*          returned from DLAGTF. */
00085 
00086 /*  B       (input) DOUBLE PRECISION array, dimension (N-1) */
00087 /*          On entry, B must contain the first super-diagonal elements of */
00088 /*          U as returned from DLAGTF. */
00089 
00090 /*  C       (input) DOUBLE PRECISION array, dimension (N-1) */
00091 /*          On entry, C must contain the sub-diagonal elements of L as */
00092 /*          returned from DLAGTF. */
00093 
00094 /*  D       (input) DOUBLE PRECISION array, dimension (N-2) */
00095 /*          On entry, D must contain the second super-diagonal elements */
00096 /*          of U as returned from DLAGTF. */
00097 
00098 /*  IN      (input) INTEGER array, dimension (N) */
00099 /*          On entry, IN must contain details of the matrix P as returned */
00100 /*          from DLAGTF. */
00101 
00102 /*  Y       (input/output) DOUBLE PRECISION array, dimension (N) */
00103 /*          On entry, the right hand side vector y. */
00104 /*          On exit, Y is overwritten by the solution vector x. */
00105 
00106 /*  TOL     (input/output) DOUBLE PRECISION */
00107 /*          On entry, with  JOB .lt. 0, TOL should be the minimum */
00108 /*          perturbation to be made to very small diagonal elements of U. */
00109 /*          TOL should normally be chosen as about eps*norm(U), where eps */
00110 /*          is the relative machine precision, but if TOL is supplied as */
00111 /*          non-positive, then it is reset to eps*max( abs( u(i,j) ) ). */
00112 /*          If  JOB .gt. 0  then TOL is not referenced. */
00113 
00114 /*          On exit, TOL is changed as described above, only if TOL is */
00115 /*          non-positive on entry. Otherwise TOL is unchanged. */
00116 
00117 /*  INFO    (output) INTEGER */
00118 /*          = 0   : successful exit */
00119 /*          .lt. 0: if INFO = -i, the i-th argument had an illegal value */
00120 /*          .gt. 0: overflow would occur when computing the INFO(th) */
00121 /*                  element of the solution vector x. This can only occur */
00122 /*                  when JOB is supplied as positive and either means */
00123 /*                  that a diagonal element of U is very small, or that */
00124 /*                  the elements of the right-hand side vector y are very */
00125 /*                  large. */
00126 
00127 /*  ===================================================================== */
00128 
00129 /*     .. Parameters .. */
00130 /*     .. */
00131 /*     .. Local Scalars .. */
00132 /*     .. */
00133 /*     .. Intrinsic Functions .. */
00134 /*     .. */
00135 /*     .. External Functions .. */
00136 /*     .. */
00137 /*     .. External Subroutines .. */
00138 /*     .. */
00139 /*     .. Executable Statements .. */
00140 
00141     /* Parameter adjustments */
00142     --y;
00143     --in;
00144     --d__;
00145     --c__;
00146     --b;
00147     --a;
00148 
00149     /* Function Body */
00150     *info = 0;
00151     if (abs(*job) > 2 || *job == 0) {
00152         *info = -1;
00153     } else if (*n < 0) {
00154         *info = -2;
00155     }
00156     if (*info != 0) {
00157         i__1 = -(*info);
00158         xerbla_("DLAGTS", &i__1);
00159         return 0;
00160     }
00161 
00162     if (*n == 0) {
00163         return 0;
00164     }
00165 
00166     eps = dlamch_("Epsilon");
00167     sfmin = dlamch_("Safe minimum");
00168     bignum = 1. / sfmin;
00169 
00170     if (*job < 0) {
00171         if (*tol <= 0.) {
00172             *tol = abs(a[1]);
00173             if (*n > 1) {
00174 /* Computing MAX */
00175                 d__1 = *tol, d__2 = abs(a[2]), d__1 = max(d__1,d__2), d__2 = 
00176                         abs(b[1]);
00177                 *tol = max(d__1,d__2);
00178             }
00179             i__1 = *n;
00180             for (k = 3; k <= i__1; ++k) {
00181 /* Computing MAX */
00182                 d__4 = *tol, d__5 = (d__1 = a[k], abs(d__1)), d__4 = max(d__4,
00183                         d__5), d__5 = (d__2 = b[k - 1], abs(d__2)), d__4 = 
00184                         max(d__4,d__5), d__5 = (d__3 = d__[k - 2], abs(d__3));
00185                 *tol = max(d__4,d__5);
00186 /* L10: */
00187             }
00188             *tol *= eps;
00189             if (*tol == 0.) {
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 = abs(ak);
00218                 if (absak < 1.) {
00219                     if (absak < sfmin) {
00220                         if (absak == 0. || abs(temp) * sfmin > absak) {
00221                             *info = k;
00222                             return 0;
00223                         } else {
00224                             temp *= bignum;
00225                             ak *= bignum;
00226                         }
00227                     } else if (abs(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 = d_sign(tol, &ak);
00246 L40:
00247                 absak = abs(ak);
00248                 if (absak < 1.) {
00249                     if (absak < sfmin) {
00250                         if (absak == 0. || abs(temp) * sfmin > absak) {
00251                             ak += pert;
00252                             pert *= 2;
00253                             goto L40;
00254                         } else {
00255                             temp *= bignum;
00256                             ak *= bignum;
00257                         }
00258                     } else if (abs(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 = abs(ak);
00284                 if (absak < 1.) {
00285                     if (absak < sfmin) {
00286                         if (absak == 0. || abs(temp) * sfmin > absak) {
00287                             *info = k;
00288                             return 0;
00289                         } else {
00290                             temp *= bignum;
00291                             ak *= bignum;
00292                         }
00293                     } else if (abs(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 = d_sign(tol, &ak);
00313 L70:
00314                 absak = abs(ak);
00315                 if (absak < 1.) {
00316                     if (absak < sfmin) {
00317                         if (absak == 0. || abs(temp) * sfmin > absak) {
00318                             ak += pert;
00319                             pert *= 2;
00320                             goto L70;
00321                         } else {
00322                             temp *= bignum;
00323                             ak *= bignum;
00324                         }
00325                     } else if (abs(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 DLAGTS */
00349 
00350     return 0;
00351 } /* dlagts_ */


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