Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

dgeequ.c

Go to the documentation of this file.
00001 /* DGEEQU.F -- translated by f2c (version 19941215).
00002    You must link the resulting object file with the libraries:
00003         -lf2c -lm   (in that order)
00004 */
00005 
00006 #include "f2c.h"
00007 
00008 /* Subroutine */ int dgeequ_(m, n, a, lda, r, c, rowcnd, colcnd, amax, info)
00009 integer *m, *n;
00010 doublereal *a;
00011 integer *lda;
00012 doublereal *r, *c, *rowcnd, *colcnd, *amax;
00013 integer *info;
00014 {
00015     /* System generated locals */
00016     integer a_dim1, a_offset, i__1, i__2;
00017     doublereal d__1, d__2, d__3;
00018 
00019     /* Local variables */
00020     static integer i, j;
00021     static doublereal rcmin, rcmax;
00022     extern doublereal dlamch_();
00023     extern /* Subroutine */ int xerbla_();
00024     static doublereal bignum, smlnum;
00025 
00026 
00027 /*  -- LAPACK routine (version 1.1) -- */
00028 /*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
00029 /*     Courant Institute, Argonne National Lab, and Rice University */
00030 /*     March 31, 1993 */
00031 
00032 /*     .. Scalar Arguments .. */
00033 /*     .. */
00034 /*     .. Array Arguments .. */
00035 /*     .. */
00036 
00037 /*  Purpose */
00038 /*  ======= */
00039 
00040 /*  DGEEQU computes row and column scalings intended to equilibrate an */
00041 /*  M-by-N matrix A and reduce its condition number.  R returns the row */
00042 /*  scale factors and C the column scale factors, chosen to try to make */
00043 /*  the largest entry in each row and column of the matrix B with */
00044 /*  elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1. */
00045 
00046 /*  R(i) and C(j) are restricted to be between SMLNUM = smallest safe */
00047 /*  number and BIGNUM = largest safe number.  Use of these scaling */
00048 /*  factors is not guaranteed to reduce the condition number of A but */
00049 /*  works well in practice. */
00050 
00051 /*  Arguments */
00052 /*  ========= */
00053 
00054 /*  M       (input) INTEGER */
00055 /*          The number of rows of the matrix A.  M >= 0. */
00056 
00057 /*  N       (input) INTEGER */
00058 /*          The number of columns of the matrix A.  N >= 0. */
00059 
00060 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00061 /*          The M-by-N matrix whose equilibration factors are */
00062 /*          to be computed. */
00063 
00064 /*  LDA     (input) INTEGER */
00065 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00066 
00067 /*  R       (output) DOUBLE PRECISION array, dimension (M) */
00068 /*          If INFO = 0 or INFO > M, R contains the row scale factors */
00069 /*          for A. */
00070 
00071 /*  C       (output) DOUBLE PRECISION array, dimension (N) */
00072 /*          If INFO = 0,  C contains the column scale factors for A. */
00073 
00074 /*  ROWCND  (output) DOUBLE PRECISION */
00075 /*          If INFO = 0 or INFO > M, ROWCND contains the ratio of the */
00076 /*          smallest R(i) to the largest R(i).  If ROWCND >= 0.1 and */
00077 /*          AMAX is neither too large nor too small, it is not worth */
00078 /*          scaling by R. */
00079 
00080 /*  COLCND  (output) DOUBLE PRECISION */
00081 /*          If INFO = 0, COLCND contains the ratio of the smallest */
00082 /*          C(i) to the largest C(i).  If COLCND >= 0.1, it is not */
00083 /*          worth scaling by C. */
00084 
00085 /*  AMAX    (output) DOUBLE PRECISION */
00086 /*          Absolute value of largest matrix element.  If AMAX is very */
00087 /*          close to overflow or very close to underflow, the matrix */
00088 /*          should be scaled. */
00089 
00090 /*  INFO    (output) INTEGER */
00091 /*          = 0:  successful exit */
00092 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00093 /*          > 0:  if INFO = i,  and i is */
00094 /*                <= M:  the i-th row of A is exactly zero */
00095 /*                >  M:  the (i-M)-th column of A is exactly zero */
00096 
00097 /*  ===================================================================== 
00098 */
00099 
00100 /*     .. Parameters .. */
00101 /*     .. */
00102 /*     .. Local Scalars .. */
00103 /*     .. */
00104 /*     .. External Functions .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. Intrinsic Functions .. */
00109 /*     .. */
00110 /*     .. Executable Statements .. */
00111 
00112 /*     Test the input parameters. */
00113 
00114     /* Parameter adjustments */
00115     a_dim1 = *lda;
00116     a_offset = a_dim1 + 1;
00117     a -= a_offset;
00118     --r;
00119     --c;
00120 
00121     /* Function Body */
00122     *info = 0;
00123     if (*m < 0) {
00124         *info = -1;
00125     } else if (*n < 0) {
00126         *info = -2;
00127     } else if (*lda < max(1,*m)) {
00128         *info = -4;
00129     }
00130     if (*info != 0) {
00131         i__1 = -(*info);
00132         xerbla_("DGEEQU", &i__1, 6L);
00133         return 0;
00134     }
00135 
00136 /*     Quick return if possible */
00137 
00138     if (*m == 0 || *n == 0) {
00139         *rowcnd = 1.;
00140         *colcnd = 1.;
00141         *amax = 0.;
00142         return 0;
00143     }
00144 
00145 /*     Get machine constants. */
00146 
00147     smlnum = dlamch_("S", 1L);
00148     bignum = 1. / smlnum;
00149 
00150 /*     Compute row scale factors. */
00151 
00152     i__1 = *m;
00153     for (i = 1; i <= i__1; ++i) {
00154         r[i] = 0.;
00155 /* L10: */
00156     }
00157 
00158 /*     Find the maximum element in each row. */
00159 
00160     i__1 = *n;
00161     for (j = 1; j <= i__1; ++j) {
00162         i__2 = *m;
00163         for (i = 1; i <= i__2; ++i) {
00164 /* Computing MAX */
00165             d__2 = r[i], d__3 = (d__1 = a[i + j * a_dim1], abs(d__1));
00166             r[i] = max(d__2,d__3);
00167 /* L20: */
00168         }
00169 /* L30: */
00170     }
00171 
00172 /*     Find the maximum and minimum scale factors. */
00173 
00174     rcmin = bignum;
00175     rcmax = 0.;
00176     i__1 = *m;
00177     for (i = 1; i <= i__1; ++i) {
00178 /* Computing MAX */
00179         d__1 = rcmax, d__2 = r[i];
00180         rcmax = max(d__1,d__2);
00181 /* Computing MIN */
00182         d__1 = rcmin, d__2 = r[i];
00183         rcmin = min(d__1,d__2);
00184 /* L40: */
00185     }
00186     *amax = rcmax;
00187 
00188     if (rcmin == 0.) {
00189 
00190 /*        Find the first zero scale factor and return an error code. 
00191 */
00192 
00193         i__1 = *m;
00194         for (i = 1; i <= i__1; ++i) {
00195             if (r[i] == 0.) {
00196                 *info = i;
00197                 return 0;
00198             }
00199 /* L50: */
00200         }
00201     } else {
00202 
00203 /*        Invert the scale factors. */
00204 
00205         i__1 = *m;
00206         for (i = 1; i <= i__1; ++i) {
00207 /* Computing MIN */
00208 /* Computing MAX */
00209             d__2 = r[i];
00210             d__1 = max(d__2,smlnum);
00211             r[i] = 1. / min(d__1,bignum);
00212 /* L60: */
00213         }
00214 
00215 /*        Compute ROWCND = min(R(I)) / max(R(I)) */
00216 
00217         *rowcnd = max(rcmin,smlnum) / min(rcmax,bignum);
00218     }
00219 
00220 /*     Compute column scale factors */
00221 
00222     i__1 = *n;
00223     for (j = 1; j <= i__1; ++j) {
00224         c[j] = 0.;
00225 /* L70: */
00226     }
00227 
00228 /*     Find the maximum element in each column, */
00229 /*     assuming the row scaling computed above. */
00230 
00231     i__1 = *n;
00232     for (j = 1; j <= i__1; ++j) {
00233         i__2 = *m;
00234         for (i = 1; i <= i__2; ++i) {
00235 /* Computing MAX */
00236             d__2 = c[j], d__3 = (d__1 = a[i + j * a_dim1], abs(d__1)) * r[i];
00237             c[j] = max(d__2,d__3);
00238 /* L80: */
00239         }
00240 /* L90: */
00241     }
00242 
00243 /*     Find the maximum and minimum scale factors. */
00244 
00245     rcmin = bignum;
00246     rcmax = 0.;
00247     i__1 = *n;
00248     for (j = 1; j <= i__1; ++j) {
00249 /* Computing MIN */
00250         d__1 = rcmin, d__2 = c[j];
00251         rcmin = min(d__1,d__2);
00252 /* Computing MAX */
00253         d__1 = rcmax, d__2 = c[j];
00254         rcmax = max(d__1,d__2);
00255 /* L100: */
00256     }
00257 
00258     if (rcmin == 0.) {
00259 
00260 /*        Find the first zero scale factor and return an error code. 
00261 */
00262 
00263         i__1 = *n;
00264         for (j = 1; j <= i__1; ++j) {
00265             if (c[j] == 0.) {
00266                 *info = *m + j;
00267                 return 0;
00268             }
00269 /* L110: */
00270         }
00271     } else {
00272 
00273 /*        Invert the scale factors. */
00274 
00275         i__1 = *n;
00276         for (j = 1; j <= i__1; ++j) {
00277 /* Computing MIN */
00278 /* Computing MAX */
00279             d__2 = c[j];
00280             d__1 = max(d__2,smlnum);
00281             c[j] = 1. / min(d__1,bignum);
00282 /* L120: */
00283         }
00284 
00285 /*        Compute COLCND = min(C(J)) / max(C(J)) */
00286 
00287         *colcnd = max(rcmin,smlnum) / min(rcmax,bignum);
00288     }
00289 
00290     return 0;
00291 
00292 /*     End of DGEEQU */
00293 
00294 } /* dgeequ_ */
00295 

Generated on Wed Sep 5 12:54:19 2007 for DSACSS Operational Code by  doxygen 1.3.9.1