bspdoc.f 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. *DECK BSPDOC
  2. SUBROUTINE BSPDOC
  3. C***BEGIN PROLOGUE BSPDOC
  4. C***PURPOSE Documentation for BSPLINE, a package of subprograms for
  5. C working with piecewise polynomial functions
  6. C in B-representation.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY E, E1A, K, Z
  9. C***TYPE ALL (BSPDOC-A)
  10. C***KEYWORDS B-SPLINE, DOCUMENTATION, SPLINES
  11. C***AUTHOR Amos, D. E., (SNLA)
  12. C***DESCRIPTION
  13. C
  14. C Abstract
  15. C BSPDOC is a non-executable, B-spline documentary routine.
  16. C The narrative describes a B-spline and the routines
  17. C necessary to manipulate B-splines at a fairly high level.
  18. C The basic package described herein is that of reference
  19. C 5 with names altered to prevent duplication and conflicts
  20. C with routines from reference 3. The call lists used here
  21. C are also different. Work vectors were added to ensure
  22. C portability and proper execution in an overlay environ-
  23. C ment. These work arrays can be used for other purposes
  24. C except as noted in BSPVN. While most of the original
  25. C routines in reference 5 were restricted to orders 20
  26. C or less, this restriction was removed from all routines
  27. C except the quadrature routine BSQAD. (See the section
  28. C below on differentiation and integration for details.)
  29. C
  30. C The subroutines referenced below are single precision
  31. C routines. Corresponding double precision versions are also
  32. C part of the package, and these are referenced by prefixing
  33. C a D in front of the single precision name. For example,
  34. C BVALU and DBVALU are the single and double precision
  35. C versions for evaluating a B-spline or any of its deriva-
  36. C tives in the B-representation.
  37. C
  38. C ****Description of B-Splines****
  39. C
  40. C A collection of polynomials of fixed degree K-1 defined on a
  41. C subdivision (X(I),X(I+1)), I=1,...,M-1 of (A,B) with X(1)=A,
  42. C X(M)=B is called a B-spline of order K. If the spline has K-2
  43. C continuous derivatives on (A,B), then the B-spline is simply
  44. C called a spline of order K. Each of the M-1 polynomial pieces
  45. C has K coefficients, making a total of K(M-1) parameters. This
  46. C B-spline and its derivatives have M-2 jumps at the subdivision
  47. C points X(I), I=2,...,M-1. Continuity requirements at these
  48. C subdivision points add constraints and reduce the number of free
  49. C parameters. If a B-spline is continuous at each of the M-2 sub-
  50. C division points, there are K(M-1)-(M-2) free parameters; if in
  51. C addition the B-spline has continuous first derivatives, there
  52. C are K(M-1)-2(M-2) free parameters, etc., until we get to a
  53. C spline where we have K(M-1)-(K-1)(M-2) = M+K-2 free parameters.
  54. C Thus, the principle is that increasing the continuity of
  55. C derivatives decreases the number of free parameters and
  56. C conversely.
  57. C
  58. C The points at which the polynomials are tied together by the
  59. C continuity conditions are called knots. If two knots are
  60. C allowed to come together at some X(I), then we say that we
  61. C have a knot of multiplicity 2 there, and the knot values are
  62. C the X(I) value. If we reverse the procedure of the first
  63. C paragraph, we find that adding a knot to increase multiplicity
  64. C increases the number of free parameters and, according to the
  65. C principle above, we thereby introduce a discontinuity in what
  66. C was the highest continuous derivative at that knot. Thus, the
  67. C number of free parameters is N = NU+K-2 where NU is the sum
  68. C of multiplicities at the X(I) values with X(1) and X(M) of
  69. C multiplicity 1 (NU = M if all knots are simple, i.e., for a
  70. C spline, all knots have multiplicity 1.) Each knot can have a
  71. C multiplicity of at most K. A B-spline is commonly written in the
  72. C B-representation
  73. C
  74. C Y(X) = sum( A(I)*B(I,X), I=1 , N)
  75. C
  76. C to show the explicit dependence of the spline on the free
  77. C parameters or coefficients A(I)=BCOEF(I) and basis functions
  78. C B(I,X). These basis functions are themselves special B-splines
  79. C which are zero except on (at most) K adjoining intervals where
  80. C each B(I,X) is positive and, in most cases, hat or bell-
  81. C shaped. In order for the nonzero part of B(1,X) to be a spline
  82. C covering (X(1),X(2)), it is necessary to put K-1 knots to the
  83. C left of A and similarly for B(N,X) to the right of B. Thus, the
  84. C total number of knots for this representation is NU+2K-2 = N+K.
  85. C These knots are carried in an array T(*) dimensioned by at least
  86. C N+K. From the construction, A=T(K) and B=T(N+1) and the spline is
  87. C defined on T(K).LE.X.LE.T(N+1). The nonzero part of each basis
  88. C function lies in the Interval (T(I),T(I+K)). In many problems
  89. C where extrapolation beyond A or B is not anticipated, it is common
  90. C practice to set T(1)=T(2)=...=T(K)=A and T(N+1)=T(N+2)=...=
  91. C T(N+K)=B. In summary, since T(K) and T(N+1) as well as
  92. C interior knots can have multiplicity K, the number of free
  93. C parameters N = sum of multiplicities - K. The fact that each
  94. C B(I,X) function is nonzero over at most K intervals means that
  95. C for a given X value, there are at most K nonzero terms of the
  96. C sum. This leads to banded matrices in linear algebra problems,
  97. C and references 3 and 6 take advantage of this in con-
  98. C structing higher level routines to achieve speed and avoid
  99. C ill-conditioning.
  100. C
  101. C ****Basic Routines****
  102. C
  103. C The basic routines which most casual users will need are those
  104. C concerned with direct evaluation of splines or B-splines.
  105. C Since the B-representation, denoted by (T,BCOEF,N,K), is
  106. C preferred because of numerical stability, the knots T(*), the
  107. C B-spline coefficients BCOEF(*), the number of coefficients N,
  108. C and the order K of the polynomial pieces (of degree K-1) are
  109. C usually given. While the knot array runs from T(1) to T(N+K),
  110. C the B-spline is normally defined on the interval T(K).LE.X.LE.
  111. C T(N+1). To evaluate the B-spline or any of its derivatives
  112. C on this interval, one can use
  113. C
  114. C Y = BVALU(T,BCOEF,N,K,ID,X,INBV,WORK)
  115. C
  116. C where ID is an integer for the ID-th derivative, 0.LE.ID.LE.K-1.
  117. C ID=0 gives the zero-th derivative or B-spline value at X.
  118. C If X.LT.T(K) or X.GT.T(N+1), whether by mistake or the result
  119. C of round off accumulation in incrementing X, BVALU gives a
  120. C diagnostic. INBV is an initialization parameter which is set
  121. C to 1 on the first call. Distinct splines require distinct
  122. C INBV parameters. WORK is a scratch vector of length at least
  123. C 3*K.
  124. C
  125. C When more conventional communication is needed for publication,
  126. C physical interpretation, etc., the B-spline coefficients can
  127. C be converted to piecewise polynomial (PP) coefficients. Thus,
  128. C the breakpoints (distinct knots) XI(*), the number of
  129. C polynomial pieces LXI, and the (right) derivatives C(*,J) at
  130. C each breakpoint XI(J) are needed to define the Taylor
  131. C expansion to the right of XI(J) on each interval XI(J).LE.
  132. C X.LT.XI(J+1), J=1,LXI where XI(1)=A and XI(LXI+1)=B.
  133. C These are obtained from the (T,BCOEF,N,K) representation by
  134. C
  135. C CALL BSPPP(T,BCOEF,N,K,LDC,C,XI,LXI,WORK)
  136. C
  137. C where LDC.GE.K is the leading dimension of the matrix C and
  138. C WORK is a scratch vector of length at least K*(N+3).
  139. C Then the PP-representation (C,XI,LXI,K) of Y(X), denoted
  140. C by Y(J,X) on each interval XI(J).LE.X.LT.XI(J+1), is
  141. C
  142. C Y(J,X) = sum( C(I,J)*((X-XI(J))**(I-1))/factorial(I-1), I=1,K)
  143. C
  144. C for J=1,...,LXI. One must view this conversion from the B-
  145. C to the PP-representation with some skepticism because the
  146. C conversion may lose significant digits when the B-spline
  147. C varies in an almost discontinuous fashion. To evaluate
  148. C the B-spline or any of its derivatives using the PP-
  149. C representation, one uses
  150. C
  151. C Y = PPVAL(LDC,C,XI,LXI,K,ID,X,INPPV)
  152. C
  153. C where ID and INPPV have the same meaning and usage as ID and
  154. C INBV in BVALU.
  155. C
  156. C To determine to what extent the conversion process loses
  157. C digits, compute the relative error ABS((Y1-Y2)/Y2) over
  158. C the X interval with Y1 from PPVAL and Y2 from BVALU. A
  159. C major reason for considering PPVAL is that evaluation is
  160. C much faster than that from BVALU.
  161. C
  162. C Recall that when multiple knots are encountered, jump type
  163. C discontinuities in the B-spline or its derivatives occur
  164. C at these knots, and we need to know that BVALU and PPVAL
  165. C return right limiting values at these knots except at
  166. C X=B where left limiting values are returned. These values
  167. C are used for the Taylor expansions about left end points of
  168. C breakpoint intervals. That is, the derivatives C(*,J) are
  169. C right derivatives. Note also that a computed X value which,
  170. C mathematically, would be a knot value may differ from the knot
  171. C by a round off error. When this happens in evaluating a dis-
  172. C continuous B-spline or some discontinuous derivative, the
  173. C value at the knot and the value at X can be radically
  174. C different. In this case, setting X to a T or XI value makes
  175. C the computation precise. For left limiting values at knots
  176. C other than X=B, see the prologues to BVALU and other
  177. C routines.
  178. C
  179. C ****Interpolation****
  180. C
  181. C BINTK is used to generate B-spline parameters (T,BCOEF,N,K)
  182. C which will interpolate the data by calls to BVALU. A similar
  183. C interpolation can also be done for cubic splines using BINT4
  184. C or the code in reference 7. If the PP-representation is given,
  185. C one can evaluate this representation at an appropriate number of
  186. C abscissas to create data then use BINTK or BINT4 to generate
  187. C the B-representation.
  188. C
  189. C ****Differentiation and Integration****
  190. C
  191. C Derivatives of B-splines are obtained from BVALU or PPVAL.
  192. C Integrals are obtained from BSQAD using the B-representation
  193. C (T,BCOEF,N,K) and PPQAD using the PP-representation (C,XI,LXI,
  194. C K). More complicated integrals involving the product of a
  195. C of a function F and some derivative of a B-spline can be
  196. C evaluated with BFQAD or PFQAD using the B- or PP- represen-
  197. C tations respectively. All quadrature routines, except for PPQAD,
  198. C are limited in accuracy to 18 digits or working precision,
  199. C whichever is smaller. PPQAD is limited to working precision
  200. C only. In addition, the order K for BSQAD is limited to 20 or
  201. C less. If orders greater than 20 are required, use BFQAD with
  202. C F(X) = 1.
  203. C
  204. C ****Extrapolation****
  205. C
  206. C Extrapolation outside the interval (A,B) can be accomplished
  207. C easily by the PP-representation using PPVAL. However,
  208. C caution should be exercised, especially when several knots
  209. C are located at A or B or when the extrapolation is carried
  210. C significantly beyond A or B. On the other hand, direct
  211. C evaluation with BVALU outside A=T(K).LE.X.LE.T(N+1)=B
  212. C produces an error message, and some manipulation of the knots
  213. C and coefficients are needed to extrapolate with BVALU. This
  214. C process is described in reference 6.
  215. C
  216. C ****Curve Fitting and Smoothing****
  217. C
  218. C Unless one has many accurate data points, direct inter-
  219. C polation is not recommended for summarizing data. The
  220. C results are often not in accordance with intuition since the
  221. C fitted curve tends to oscillate through the set of points.
  222. C Monotone splines (reference 7) can help curb this undulating
  223. C tendency but constrained least squares is more likely to give an
  224. C acceptable fit with fewer parameters. Subroutine FC, des-
  225. C cribed in reference 6, is recommended for this purpose. The
  226. C output from this fitting process is the B-representation.
  227. C
  228. C **** Routines in the B-Spline Package ****
  229. C
  230. C Single Precision Routines
  231. C
  232. C The subroutines referenced below are SINGLE PRECISION
  233. C routines. Corresponding DOUBLE PRECISION versions are also
  234. C part of the package and these are referenced by prefixing
  235. C a D in front of the single precision name. For example,
  236. C BVALU and DBVALU are the SINGLE and DOUBLE PRECISION
  237. C versions for evaluating a B-spline or any of its deriva-
  238. C tives in the B-representation.
  239. C
  240. C BINT4 - interpolates with splines of order 4
  241. C BINTK - interpolates with splines of order k
  242. C BSQAD - integrates the B-representation on subintervals
  243. C PPQAD - integrates the PP-representation
  244. C BFQAD - integrates the product of a function F and any spline
  245. C derivative in the B-representation
  246. C PFQAD - integrates the product of a function F and any spline
  247. C derivative in the PP-representation
  248. C BVALU - evaluates the B-representation or a derivative
  249. C PPVAL - evaluates the PP-representation or a derivative
  250. C INTRV - gets the largest index of the knot to the left of x
  251. C BSPPP - converts from B- to PP-representation
  252. C BSPVD - computes nonzero basis functions and derivatives at x
  253. C BSPDR - sets up difference array for BSPEV
  254. C BSPEV - evaluates the B-representation and derivatives
  255. C BSPVN - called by BSPEV, BSPVD, BSPPP and BINTK for function and
  256. C derivative evaluations
  257. C Auxiliary Routines
  258. C
  259. C BSGQ8,PPGQ8,BNSLV,BNFAC,XERMSG,DBSGQ8,DPPGQ8,DBNSLV,DBNFAC
  260. C
  261. C Machine Dependent Routines
  262. C
  263. C I1MACH, R1MACH, D1MACH
  264. C
  265. C***REFERENCES 1. D. E. Amos, Computation with splines and
  266. C B-splines, Report SAND78-1968, Sandia
  267. C Laboratories, March 1979.
  268. C 2. D. E. Amos, Quadrature subroutines for splines and
  269. C B-splines, Report SAND79-1825, Sandia Laboratories,
  270. C December 1979.
  271. C 3. Carl de Boor, A Practical Guide to Splines, Applied
  272. C Mathematics Series 27, Springer-Verlag, New York,
  273. C 1978.
  274. C 4. Carl de Boor, On calculating with B-Splines, Journal
  275. C of Approximation Theory 6, (1972), pp. 50-62.
  276. C 5. Carl de Boor, Package for calculating with B-splines,
  277. C SIAM Journal on Numerical Analysis 14, 3 (June 1977),
  278. C pp. 441-472.
  279. C 6. R. J. Hanson, Constrained least squares curve fitting
  280. C to discrete data using B-splines, a users guide,
  281. C Report SAND78-1291, Sandia Laboratories, December
  282. C 1978.
  283. C 7. F. N. Fritsch and R. E. Carlson, Monotone piecewise
  284. C cubic interpolation, SIAM Journal on Numerical Ana-
  285. C lysis 17, 2 (April 1980), pp. 238-246.
  286. C***ROUTINES CALLED (NONE)
  287. C***REVISION HISTORY (YYMMDD)
  288. C 810223 DATE WRITTEN
  289. C 861211 REVISION DATE from Version 3.2
  290. C 891214 Prologue converted to Version 4.0 format. (BAB)
  291. C 900723 PURPOSE section revised. (WRB)
  292. C 920501 Reformatted the REFERENCES section. (WRB)
  293. C***END PROLOGUE BSPDOC
  294. C***FIRST EXECUTABLE STATEMENT BSPDOC
  295. RETURN
  296. END