cv.f 5.1 KB

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