1 real function bvalue ( t, bcoef, n, k, x, jderiv )
2 c from * a practical guide to splines * by c. de boor
5 calculates value at x of jderiv-th derivative of spline from b-repr.
6 c the spline is taken to be continuous from the right, EXCEPT at the
7 c rightmost knot, where it is taken to be continuous from the left.
9 c****** i n p u t ******
10 c t, bcoef, n, k......forms the b-representation of the spline f to
11 c be evaluated. specifically,
12 c t.....knot sequence, of length n+k, assumed nondecreasing.
13 c bcoef.....b-coefficient sequence, of length n .
14 c n.....length of bcoef and dimension of spline(k,t),
15 c a s s u m e d positive .
16 c k.....order of the spline .
18 c w a r n i n g . . . the restriction k .le. kmax (=20) is imposed
19 c arbitrarily by the dimension statement for aj, dl, dr below,
20 c but is n o w h e r e c h e c k e d for.
22 c x.....the point at which to evaluate .
23 c jderiv.....integer giving the order of the derivative to be evaluated
24 c a s s u m e d to be zero or positive.
26 c****** o u t p u t ******
27 c bvalue.....the value of the (jderiv)-th derivative of f at x .
29 c****** m e t h o d ******
30 c The nontrivial knot interval (t(i),t(i+1)) containing x is lo-
31 c cated with the aid of interv . The k b-coeffs of f relevant for
32 c this interval are then obtained from bcoef (or taken to be zero if
33 c not explicitly available) and are then differenced jderiv times to
34 c obtain the b-coeffs of (d**jderiv)f relevant for that interval.
35 c Precisely, with j = jderiv, we have from x.(12) of the text that
37 c (d**j)f = sum ( bcoef(.,j)*b(.,k-j,t) )
40 c / bcoef(.), , j .eq. 0
42 c bcoef(.,j) = / bcoef(.,j-1) - bcoef(.-1,j-1)
43 c / ----------------------------- , j .gt. 0
44 c / (t(.+k-j) - t(.))/(k-j)
46 c Then, we use repeatedly the fact that
48 c sum ( a(.)*b(.,m,t)(x) ) = sum ( a(.,x)*b(.,m-1,t)(x) )
50 c (x - t(.))*a(.) + (t(.+m-1) - x)*a(.-1)
51 c a(.,x) = ---------------------------------------
52 c (x - t(.)) + (t(.+m-1) - x)
54 c to write (d**j)f(x) eventually as a linear combination of b-splines
55 c of order 1 , and the coefficient for b(i,1,t)(x) must then be the
56 c desired number (d**j)f(x). (see x.(17)-(19) of text).
58 integer jderiv,k,n, i,ilo,imk,j,jc,jcmin,jcmax,jj,kmax,kmj,km1
61 real bcoef(n),t(n+k),x, aj(kmax),dl(kmax),dr(kmax),fkmj
63 if (jderiv .ge. k) go to 99
65 c *** Find i s.t. 1 .le. i .lt. n+k and t(i) .lt. t(i+1) and
66 c t(i) .le. x .lt. t(i+1) . If no such i can be found, x lies
67 c outside the support of the spline f , hence bvalue = 0.
68 c (The asymmetry in this choice of i makes f rightcontinuous, except
69 c at t(n+k) where it is leftcontinuous.)
70 call interv ( t, n+k, x, i, mflag )
71 if (mflag .ne. 0) go to 99
72 c *** if k = 1 (and jderiv = 0), bvalue = bcoef(i).
74 if (km1 .gt. 0) go to 1
78 c *** store the k b-spline coefficients relevant for the knot interval
79 c (t(i),t(i+1)) in aj(1),...,aj(k) and compute dl(j) = x - t(i+1-j),
80 c dr(j) = t(i+j) - x, j=1,...,k-1 . set any of the aj not obtainable
81 c from input to zero. set any t.s not obtainable equal to t(1) or
82 c to t(n+k) appropriately.
85 if (imk .ge. 0) go to 8
88 5 dl(j) = x - t(i+1-j)
94 9 dl(j) = x - t(i+1-j)
98 if (nmi .ge. 0) go to 18
101 15 dr(j) = t(i+j) - x
107 19 dr(j) = t(i+j) - x
109 20 do 21 jc=jcmin,jcmax
110 21 aj(jc) = bcoef(imk + jc)
112 c *** difference the coefficients jderiv times.
113 if (jderiv .eq. 0) go to 30
119 aj(jj) = ((aj(jj+1) - aj(jj))/(dl(ilo) + dr(jj)))*fkmj
122 c *** compute value at x in (t(i),t(i+1)) of jderiv-th derivative,
123 c given its relevant b-spline coeffs in aj(1),...,aj(k-jderiv).
124 30 if (jderiv .eq. km1) go to 39
130 aj(jj) = (aj(jj+1)*dl(ilo) + aj(jj)*dr(jj))/(dl(ilo)+dr(jj))