dcv.f 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. *DECK DCV
  2. DOUBLE PRECISION FUNCTION DCV (XVAL, NDATA, NCONST, NORD, NBKPT,
  3. + BKPT, W)
  4. C***BEGIN PROLOGUE DCV
  5. C***PURPOSE Evaluate the variance function of the curve obtained
  6. C by the constrained B-spline fitting subprogram DFC.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY L7A3
  9. C***TYPE DOUBLE PRECISION (CV-S, DCV-D)
  10. C***KEYWORDS ANALYSIS OF COVARIANCE, B-SPLINE,
  11. C CONSTRAINED LEAST SQUARES, CURVE FITTING
  12. C***AUTHOR Hanson, R. J., (SNLA)
  13. C***DESCRIPTION
  14. C
  15. C DCV( ) is a companion function subprogram for DFC( ). The
  16. C documentation for DFC( ) has complete usage instructions.
  17. C
  18. C DCV( ) is used to evaluate the variance function of the curve
  19. C obtained by the constrained B-spline fitting subprogram, DFC( ).
  20. C The variance function defines the square of the probable error
  21. C of the fitted curve at any point, XVAL. One can use the square
  22. C root of this variance function to determine a probable error band
  23. C around the fitted curve.
  24. C
  25. C DCV( ) is used after a call to DFC( ). MODE, an input variable to
  26. C DFC( ), is used to indicate if the variance function is desired.
  27. C In order to use DCV( ), MODE must equal 2 or 4 on input to DFC( ).
  28. C MODE is also used as an output flag from DFC( ). Check to make
  29. C sure that MODE = 0 after calling DFC( ), indicating a successful
  30. C constrained curve fit. The array SDDATA, as input to DFC( ), must
  31. C also be defined with the standard deviation or uncertainty of the
  32. C Y values to use DCV( ).
  33. C
  34. C To evaluate the variance function after calling DFC( ) as stated
  35. C above, use DCV( ) as shown here
  36. C
  37. C VAR=DCV(XVAL,NDATA,NCONST,NORD,NBKPT,BKPT,W)
  38. C
  39. C The variance function is given by
  40. C
  41. C VAR=(transpose of B(XVAL))*C*B(XVAL)/DBLE(MAX(NDATA-N,1))
  42. C
  43. C where N = NBKPT - NORD.
  44. C
  45. C The vector B(XVAL) is the B-spline basis function values at
  46. C X=XVAL. The covariance matrix, C, of the solution coefficients
  47. C accounts only for the least squares equations and the explicitly
  48. C stated equality constraints. This fact must be considered when
  49. C interpreting the variance function from a data fitting problem
  50. C that has inequality constraints on the fitted curve.
  51. C
  52. C All the variables in the calling sequence for DCV( ) are used in
  53. C DFC( ) except the variable XVAL. Do not change the values of
  54. C these variables between the call to DFC( ) and the use of DCV( ).
  55. C
  56. C The following is a brief description of the variables
  57. C
  58. C XVAL The point where the variance is desired, a double
  59. C precision variable.
  60. C
  61. C NDATA The number of discrete (X,Y) pairs for which DFC( )
  62. C calculated a piece-wise polynomial curve.
  63. C
  64. C NCONST The number of conditions that constrained the B-spline in
  65. C DFC( ).
  66. C
  67. C NORD The order of the B-spline used in DFC( ).
  68. C The value of NORD must satisfy 1 < NORD < 20 .
  69. C
  70. C (The order of the spline is one more than the degree of
  71. C the piece-wise polynomial defined on each interval. This
  72. C is consistent with the B-spline package convention. For
  73. C example, NORD=4 when we are using piece-wise cubics.)
  74. C
  75. C NBKPT The number of knots in the array BKPT(*).
  76. C The value of NBKPT must satisfy NBKPT .GE. 2*NORD.
  77. C
  78. C BKPT(*) The double precision array of knots. Normally the problem
  79. C data interval will be included between the limits
  80. C BKPT(NORD) and BKPT(NBKPT-NORD+1). The additional end
  81. C knots BKPT(I),I=1,...,NORD-1 and I=NBKPT-NORD+2,...,NBKPT,
  82. C are required by DFC( ) to compute the functions used to
  83. C fit the data.
  84. C
  85. C W(*) Double precision work array as used in DFC( ). See DFC( )
  86. C for the required length of W(*). The contents of W(*)
  87. C must not be modified by the user if the variance function
  88. C is desired.
  89. C
  90. C***REFERENCES R. J. Hanson, Constrained least squares curve fitting
  91. C to discrete data using B-splines, a users guide,
  92. C Report SAND78-1291, Sandia Laboratories, December
  93. C 1978.
  94. C***ROUTINES CALLED DDOT, DFSPVN
  95. C***REVISION HISTORY (YYMMDD)
  96. C 780801 DATE WRITTEN
  97. C 890531 Changed all specific intrinsics to generic. (WRB)
  98. C 890831 Modified array declarations. (WRB)
  99. C 890911 Removed unnecessary intrinsics. (WRB)
  100. C 891006 Cosmetic changes to prologue. (WRB)
  101. C 891006 REVISION DATE from Version 3.2
  102. C 891214 Prologue converted to Version 4.0 format. (BAB)
  103. C 920501 Reformatted the REFERENCES section. (WRB)
  104. C***END PROLOGUE DCV
  105. INTEGER I, ILEFT, IP, IS, LAST, MDG, MDW, N, NBKPT, NCONST,
  106. * NDATA, NORD
  107. DOUBLE PRECISION BKPT, DDOT, V, W, XVAL, ZERO
  108. DIMENSION BKPT(*),W(*),V(40)
  109. C***FIRST EXECUTABLE STATEMENT DCV
  110. ZERO = 0.0D0
  111. MDG = NBKPT - NORD + 3
  112. MDW = NBKPT - NORD + 1 + NCONST
  113. IS = MDG*(NORD + 1) + 2*MAX(NDATA,NBKPT) + NBKPT + NORD**2
  114. LAST = NBKPT - NORD + 1
  115. ILEFT = NORD
  116. 10 IF (XVAL .LT. BKPT(ILEFT+1) .OR. ILEFT .GE. LAST - 1) GO TO 20
  117. ILEFT = ILEFT + 1
  118. GO TO 10
  119. 20 CONTINUE
  120. CALL DFSPVN(BKPT,NORD,1,XVAL,ILEFT,V(NORD+1))
  121. ILEFT = ILEFT - NORD + 1
  122. IP = MDW*(ILEFT - 1) + ILEFT + IS
  123. N = NBKPT - NORD
  124. DO 30 I = 1, NORD
  125. V(I) = DDOT(NORD,W(IP),1,V(NORD+1),1)
  126. IP = IP + MDW
  127. 30 CONTINUE
  128. DCV = MAX(DDOT(NORD,V,1,V(NORD+1),1),ZERO)
  129. C
  130. C SCALE THE VARIANCE SO IT IS AN UNBIASED ESTIMATE.
  131. DCV = DCV/MAX(NDATA-N,1)
  132. RETURN
  133. END