sgtt01.c
Go to the documentation of this file.
00001 /* sgtt01.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 sgtt01_(integer *n, real *dl, real *d__, real *du, real *
00017         dlf, real *df, real *duf, real *du2, integer *ipiv, real *work, 
00018         integer *ldwork, real *rwork, real *resid)
00019 {
00020     /* System generated locals */
00021     integer work_dim1, work_offset, i__1, i__2;
00022 
00023     /* Local variables */
00024     integer i__, j;
00025     real li;
00026     integer ip;
00027     real eps, anorm;
00028     integer lastj;
00029     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00030             integer *), saxpy_(integer *, real *, real *, integer *, real *, 
00031             integer *);
00032     extern doublereal slamch_(char *), slangt_(char *, integer *, 
00033             real *, real *, real *), slanhs_(char *, integer *, real *
00034 , integer *, real *);
00035 
00036 
00037 /*  -- LAPACK test routine (version 3.1) -- */
00038 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00039 /*     November 2006 */
00040 
00041 /*     .. Scalar Arguments .. */
00042 /*     .. */
00043 /*     .. Array Arguments .. */
00044 /*     .. */
00045 
00046 /*  Purpose */
00047 /*  ======= */
00048 
00049 /*  SGTT01 reconstructs a tridiagonal matrix A from its LU factorization */
00050 /*  and computes the residual */
00051 /*     norm(L*U - A) / ( norm(A) * EPS ), */
00052 /*  where EPS is the machine epsilon. */
00053 
00054 /*  Arguments */
00055 /*  ========= */
00056 
00057 /*  N       (input) INTEGTER */
00058 /*          The order of the matrix A.  N >= 0. */
00059 
00060 /*  DL      (input) REAL array, dimension (N-1) */
00061 /*          The (n-1) sub-diagonal elements of A. */
00062 
00063 /*  D       (input) REAL array, dimension (N) */
00064 /*          The diagonal elements of A. */
00065 
00066 /*  DU      (input) REAL array, dimension (N-1) */
00067 /*          The (n-1) super-diagonal elements of A. */
00068 
00069 /*  DLF     (input) REAL array, dimension (N-1) */
00070 /*          The (n-1) multipliers that define the matrix L from the */
00071 /*          LU factorization of A. */
00072 
00073 /*  DF      (input) REAL array, dimension (N) */
00074 /*          The n diagonal elements of the upper triangular matrix U from */
00075 /*          the LU factorization of A. */
00076 
00077 /*  DUF     (input) REAL array, dimension (N-1) */
00078 /*          The (n-1) elements of the first super-diagonal of U. */
00079 
00080 /*  DU2F    (input) REAL array, dimension (N-2) */
00081 /*          The (n-2) elements of the second super-diagonal of U. */
00082 
00083 /*  IPIV    (input) INTEGER array, dimension (N) */
00084 /*          The pivot indices; for 1 <= i <= n, row i of the matrix was */
00085 /*          interchanged with row IPIV(i).  IPIV(i) will always be either */
00086 /*          i or i+1; IPIV(i) = i indicates a row interchange was not */
00087 /*          required. */
00088 
00089 /*  WORK    (workspace) REAL array, dimension (LDWORK,N) */
00090 
00091 /*  LDWORK  (input) INTEGER */
00092 /*          The leading dimension of the array WORK.  LDWORK >= max(1,N). */
00093 
00094 /*  RWORK   (workspace) REAL array, dimension (N) */
00095 
00096 /*  RESID   (output) REAL */
00097 /*          The scaled residual:  norm(L*U - A) / (norm(A) * EPS) */
00098 
00099 /*  ===================================================================== */
00100 
00101 /*     .. Parameters .. */
00102 /*     .. */
00103 /*     .. Local Scalars .. */
00104 /*     .. */
00105 /*     .. External Functions .. */
00106 /*     .. */
00107 /*     .. Intrinsic Functions .. */
00108 /*     .. */
00109 /*     .. External Subroutines .. */
00110 /*     .. */
00111 /*     .. Executable Statements .. */
00112 
00113 /*     Quick return if possible */
00114 
00115     /* Parameter adjustments */
00116     --dl;
00117     --d__;
00118     --du;
00119     --dlf;
00120     --df;
00121     --duf;
00122     --du2;
00123     --ipiv;
00124     work_dim1 = *ldwork;
00125     work_offset = 1 + work_dim1;
00126     work -= work_offset;
00127     --rwork;
00128 
00129     /* Function Body */
00130     if (*n <= 0) {
00131         *resid = 0.f;
00132         return 0;
00133     }
00134 
00135     eps = slamch_("Epsilon");
00136 
00137 /*     Copy the matrix U to WORK. */
00138 
00139     i__1 = *n;
00140     for (j = 1; j <= i__1; ++j) {
00141         i__2 = *n;
00142         for (i__ = 1; i__ <= i__2; ++i__) {
00143             work[i__ + j * work_dim1] = 0.f;
00144 /* L10: */
00145         }
00146 /* L20: */
00147     }
00148     i__1 = *n;
00149     for (i__ = 1; i__ <= i__1; ++i__) {
00150         if (i__ == 1) {
00151             work[i__ + i__ * work_dim1] = df[i__];
00152             if (*n >= 2) {
00153                 work[i__ + (i__ + 1) * work_dim1] = duf[i__];
00154             }
00155             if (*n >= 3) {
00156                 work[i__ + (i__ + 2) * work_dim1] = du2[i__];
00157             }
00158         } else if (i__ == *n) {
00159             work[i__ + i__ * work_dim1] = df[i__];
00160         } else {
00161             work[i__ + i__ * work_dim1] = df[i__];
00162             work[i__ + (i__ + 1) * work_dim1] = duf[i__];
00163             if (i__ < *n - 1) {
00164                 work[i__ + (i__ + 2) * work_dim1] = du2[i__];
00165             }
00166         }
00167 /* L30: */
00168     }
00169 
00170 /*     Multiply on the left by L. */
00171 
00172     lastj = *n;
00173     for (i__ = *n - 1; i__ >= 1; --i__) {
00174         li = dlf[i__];
00175         i__1 = lastj - i__ + 1;
00176         saxpy_(&i__1, &li, &work[i__ + i__ * work_dim1], ldwork, &work[i__ + 
00177                 1 + i__ * work_dim1], ldwork);
00178         ip = ipiv[i__];
00179         if (ip == i__) {
00180 /* Computing MIN */
00181             i__1 = i__ + 2;
00182             lastj = min(i__1,*n);
00183         } else {
00184             i__1 = lastj - i__ + 1;
00185             sswap_(&i__1, &work[i__ + i__ * work_dim1], ldwork, &work[i__ + 1 
00186                     + i__ * work_dim1], ldwork);
00187         }
00188 /* L40: */
00189     }
00190 
00191 /*     Subtract the matrix A. */
00192 
00193     work[work_dim1 + 1] -= d__[1];
00194     if (*n > 1) {
00195         work[(work_dim1 << 1) + 1] -= du[1];
00196         work[*n + (*n - 1) * work_dim1] -= dl[*n - 1];
00197         work[*n + *n * work_dim1] -= d__[*n];
00198         i__1 = *n - 1;
00199         for (i__ = 2; i__ <= i__1; ++i__) {
00200             work[i__ + (i__ - 1) * work_dim1] -= dl[i__ - 1];
00201             work[i__ + i__ * work_dim1] -= d__[i__];
00202             work[i__ + (i__ + 1) * work_dim1] -= du[i__];
00203 /* L50: */
00204         }
00205     }
00206 
00207 /*     Compute the 1-norm of the tridiagonal matrix A. */
00208 
00209     anorm = slangt_("1", n, &dl[1], &d__[1], &du[1]);
00210 
00211 /*     Compute the 1-norm of WORK, which is only guaranteed to be */
00212 /*     upper Hessenberg. */
00213 
00214     *resid = slanhs_("1", n, &work[work_offset], ldwork, &rwork[1])
00215             ;
00216 
00217 /*     Compute norm(L*U - A) / (norm(A) * EPS) */
00218 
00219     if (anorm <= 0.f) {
00220         if (*resid != 0.f) {
00221             *resid = 1.f / eps;
00222         }
00223     } else {
00224         *resid = *resid / anorm / eps;
00225     }
00226 
00227     return 0;
00228 
00229 /*     End of SGTT01 */
00230 
00231 } /* sgtt01_ */


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