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


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