sptt01.c
上传用户:szlbkj
上传日期:2009-03-19
资源大小:26133k
文件大小:4k
源码类别:

数学计算

开发平台:

Visual C++

  1. #include "blaswrap.h"
  2. /*  -- translated by f2c (version 19990503).
  3.    You must link the resulting object file with the libraries:
  4. -lf2c -lm   (in that order)
  5. */
  6. #include "f2c.h"
  7. /* Subroutine */ int sptt01_(integer *n, real *d__, real *e, real *df, real *
  8. ef, real *work, real *resid)
  9. {
  10.     /* System generated locals */
  11.     integer i__1;
  12.     real r__1, r__2, r__3, r__4, r__5;
  13.     /* Local variables */
  14.     static integer i__;
  15.     static real anorm, de;
  16.     extern doublereal slamch_(char *);
  17.     static real eps;
  18. /*  -- LAPACK test routine (version 3.0) --   
  19.        Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
  20.        Courant Institute, Argonne National Lab, and Rice University   
  21.        February 29, 1992   
  22.     Purpose   
  23.     =======   
  24.     SPTT01 reconstructs a tridiagonal matrix A from its L*D*L'   
  25.     factorization and computes the residual   
  26.        norm(L*D*L' - A) / ( n * norm(A) * EPS ),   
  27.     where EPS is the machine epsilon.   
  28.     Arguments   
  29.     =========   
  30.     N       (input) INTEGTER   
  31.             The order of the matrix A.   
  32.     D       (input) REAL array, dimension (N)   
  33.             The n diagonal elements of the tridiagonal matrix A.   
  34.     E       (input) REAL array, dimension (N-1)   
  35.             The (n-1) subdiagonal elements of the tridiagonal matrix A.   
  36.     DF      (input) REAL array, dimension (N)   
  37.             The n diagonal elements of the factor L from the L*D*L'   
  38.             factorization of A.   
  39.     EF      (input) REAL array, dimension (N-1)   
  40.             The (n-1) subdiagonal elements of the factor L from the   
  41.             L*D*L' factorization of A.   
  42.     WORK    (workspace) REAL array, dimension (2*N)   
  43.     RESID   (output) REAL   
  44.             norm(L*D*L' - A) / (n * norm(A) * EPS)   
  45.     =====================================================================   
  46.        Quick return if possible   
  47.        Parameter adjustments */
  48.     --work;
  49.     --ef;
  50.     --df;
  51.     --e;
  52.     --d__;
  53.     /* Function Body */
  54.     if (*n <= 0) {
  55. *resid = 0.f;
  56. return 0;
  57.     }
  58.     eps = slamch_("Epsilon");
  59. /*     Construct the difference L*D*L' - A. */
  60.     work[1] = df[1] - d__[1];
  61.     i__1 = *n - 1;
  62.     for (i__ = 1; i__ <= i__1; ++i__) {
  63. de = df[i__] * ef[i__];
  64. work[*n + i__] = de - e[i__];
  65. work[i__ + 1] = de * ef[i__] + df[i__ + 1] - d__[i__ + 1];
  66. /* L10: */
  67.     }
  68. /*     Compute the 1-norms of the tridiagonal matrices A and WORK. */
  69.     if (*n == 1) {
  70. anorm = d__[1];
  71. *resid = dabs(work[1]);
  72.     } else {
  73. /* Computing MAX */
  74. r__2 = d__[1] + dabs(e[1]), r__3 = d__[*n] + (r__1 = e[*n - 1], dabs(
  75. r__1));
  76. anorm = dmax(r__2,r__3);
  77. /* Computing MAX */
  78. r__4 = dabs(work[1]) + (r__1 = work[*n + 1], dabs(r__1)), r__5 = (
  79. r__2 = work[*n], dabs(r__2)) + (r__3 = work[(*n << 1) - 1], 
  80. dabs(r__3));
  81. *resid = dmax(r__4,r__5);
  82. i__1 = *n - 1;
  83. for (i__ = 2; i__ <= i__1; ++i__) {
  84. /* Computing MAX */
  85.     r__3 = anorm, r__4 = d__[i__] + (r__1 = e[i__], dabs(r__1)) + (
  86.     r__2 = e[i__ - 1], dabs(r__2));
  87.     anorm = dmax(r__3,r__4);
  88. /* Computing MAX */
  89.     r__4 = *resid, r__5 = (r__1 = work[i__], dabs(r__1)) + (r__2 = 
  90.     work[*n + i__ - 1], dabs(r__2)) + (r__3 = work[*n + i__], 
  91.     dabs(r__3));
  92.     *resid = dmax(r__4,r__5);
  93. /* L20: */
  94. }
  95.     }
  96. /*     Compute norm(L*D*L' - A) / (n * norm(A) * EPS) */
  97.     if (anorm <= 0.f) {
  98. if (*resid != 0.f) {
  99.     *resid = 1.f / eps;
  100. }
  101.     } else {
  102. *resid = *resid / (real) (*n) / anorm / eps;
  103.     }
  104.     return 0;
  105. /*     End of SPTT01 */
  106. } /* sptt01_ */