sgbt02.c
Go to the documentation of this file.
00001 /* sgbt02.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 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static real c_b8 = -1.f;
00020 static real c_b10 = 1.f;
00021 
00022 /* Subroutine */ int sgbt02_(char *trans, integer *m, integer *n, integer *kl, 
00023          integer *ku, integer *nrhs, real *a, integer *lda, real *x, integer *
00024         ldx, real *b, integer *ldb, real *resid)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, 
00028             i__3;
00029     real r__1, r__2;
00030 
00031     /* Local variables */
00032     integer j, i1, i2, n1, kd;
00033     real eps;
00034     extern logical lsame_(char *, char *);
00035     real anorm, bnorm;
00036     extern /* Subroutine */ int sgbmv_(char *, integer *, integer *, integer *
00037 , integer *, real *, real *, integer *, real *, integer *, real *, 
00038              real *, integer *);
00039     extern doublereal sasum_(integer *, real *, integer *);
00040     real xnorm;
00041     extern doublereal slamch_(char *);
00042 
00043 
00044 /*  -- LAPACK test routine (version 3.1) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  SGBT02 computes the residual for a solution of a banded system of */
00057 /*  equations  A*x = b  or  A'*x = b: */
00058 /*     RESID = norm( B - A*X ) / ( norm(A) * norm(X) * EPS). */
00059 /*  where EPS is the machine precision. */
00060 
00061 /*  Arguments */
00062 /*  ========= */
00063 
00064 /*  TRANS   (input) CHARACTER*1 */
00065 /*          Specifies the form of the system of equations: */
00066 /*          = 'N':  A *x = b */
00067 /*          = 'T':  A'*x = b, where A' is the transpose of A */
00068 /*          = 'C':  A'*x = b, where A' is the transpose of A */
00069 
00070 /*  M       (input) INTEGER */
00071 /*          The number of rows of the matrix A.  M >= 0. */
00072 
00073 /*  N       (input) INTEGER */
00074 /*          The number of columns of the matrix A.  N >= 0. */
00075 
00076 /*  KL      (input) INTEGER */
00077 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00078 
00079 /*  KU      (input) INTEGER */
00080 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00081 
00082 /*  NRHS    (input) INTEGER */
00083 /*          The number of columns of B.  NRHS >= 0. */
00084 
00085 /*  A       (input) REAL array, dimension (LDA,N) */
00086 /*          The original matrix A in band storage, stored in rows 1 to */
00087 /*          KL+KU+1. */
00088 
00089 /*  LDA     (input) INTEGER */
00090 /*          The leading dimension of the array A.  LDA >= max(1,KL+KU+1). */
00091 
00092 /*  X       (input) REAL array, dimension (LDX,NRHS) */
00093 /*          The computed solution vectors for the system of linear */
00094 /*          equations. */
00095 
00096 /*  LDX     (input) INTEGER */
00097 /*          The leading dimension of the array X.  If TRANS = 'N', */
00098 /*          LDX >= max(1,N); if TRANS = 'T' or 'C', LDX >= max(1,M). */
00099 
00100 /*  B       (input/output) REAL array, dimension (LDB,NRHS) */
00101 /*          On entry, the right hand side vectors for the system of */
00102 /*          linear equations. */
00103 /*          On exit, B is overwritten with the difference B - A*X. */
00104 
00105 /*  LDB     (input) INTEGER */
00106 /*          The leading dimension of the array B.  IF TRANS = 'N', */
00107 /*          LDB >= max(1,M); if TRANS = 'T' or 'C', LDB >= max(1,N). */
00108 
00109 /*  RESID   (output) REAL */
00110 /*          The maximum over the number of right hand sides of */
00111 /*          norm(B - A*X) / ( norm(A) * norm(X) * EPS ). */
00112 
00113 /*  ===================================================================== */
00114 
00115 /*     .. Parameters .. */
00116 /*     .. */
00117 /*     .. Local Scalars .. */
00118 /*     .. */
00119 /*     .. External Functions .. */
00120 /*     .. */
00121 /*     .. External Subroutines .. */
00122 /*     .. */
00123 /*     .. Intrinsic Functions .. */
00124 /*     .. */
00125 /*     .. Executable Statements .. */
00126 
00127 /*     Quick return if N = 0 pr NRHS = 0 */
00128 
00129     /* Parameter adjustments */
00130     a_dim1 = *lda;
00131     a_offset = 1 + a_dim1;
00132     a -= a_offset;
00133     x_dim1 = *ldx;
00134     x_offset = 1 + x_dim1;
00135     x -= x_offset;
00136     b_dim1 = *ldb;
00137     b_offset = 1 + b_dim1;
00138     b -= b_offset;
00139 
00140     /* Function Body */
00141     if (*m <= 0 || *n <= 0 || *nrhs <= 0) {
00142         *resid = 0.f;
00143         return 0;
00144     }
00145 
00146 /*     Exit with RESID = 1/EPS if ANORM = 0. */
00147 
00148     eps = slamch_("Epsilon");
00149     kd = *ku + 1;
00150     anorm = 0.f;
00151     i__1 = *n;
00152     for (j = 1; j <= i__1; ++j) {
00153 /* Computing MAX */
00154         i__2 = kd + 1 - j;
00155         i1 = max(i__2,1);
00156 /* Computing MIN */
00157         i__2 = kd + *m - j, i__3 = *kl + kd;
00158         i2 = min(i__2,i__3);
00159 /* Computing MAX */
00160         i__2 = i2 - i1 + 1;
00161         r__1 = anorm, r__2 = sasum_(&i__2, &a[i1 + j * a_dim1], &c__1);
00162         anorm = dmax(r__1,r__2);
00163 /* L10: */
00164     }
00165     if (anorm <= 0.f) {
00166         *resid = 1.f / eps;
00167         return 0;
00168     }
00169 
00170     if (lsame_(trans, "T") || lsame_(trans, "C")) {
00171         n1 = *n;
00172     } else {
00173         n1 = *m;
00174     }
00175 
00176 /*     Compute  B - A*X (or  B - A'*X ) */
00177 
00178     i__1 = *nrhs;
00179     for (j = 1; j <= i__1; ++j) {
00180         sgbmv_(trans, m, n, kl, ku, &c_b8, &a[a_offset], lda, &x[j * x_dim1 + 
00181                 1], &c__1, &c_b10, &b[j * b_dim1 + 1], &c__1);
00182 /* L20: */
00183     }
00184 
00185 /*     Compute the maximum over the number of right hand sides of */
00186 /*        norm(B - A*X) / ( norm(A) * norm(X) * EPS ). */
00187 
00188     *resid = 0.f;
00189     i__1 = *nrhs;
00190     for (j = 1; j <= i__1; ++j) {
00191         bnorm = sasum_(&n1, &b[j * b_dim1 + 1], &c__1);
00192         xnorm = sasum_(&n1, &x[j * x_dim1 + 1], &c__1);
00193         if (xnorm <= 0.f) {
00194             *resid = 1.f / eps;
00195         } else {
00196 /* Computing MAX */
00197             r__1 = *resid, r__2 = bnorm / anorm / xnorm / eps;
00198             *resid = dmax(r__1,r__2);
00199         }
00200 /* L30: */
00201     }
00202 
00203     return 0;
00204 
00205 /*     End of SGBT02 */
00206 
00207 } /* sgbt02_ */


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