Cubic Spline Interpolation1 We have tabulated values for y and y’’ leading to the approximation. y x A x; x j , x j 1 y j B x; x j , x j 1 y j 1 C x; x j , x j 1 y '' j D x; x j , x j 1 y '' j 1 (1.1) Where A x; x j , x j 1 AL j x j 1 x x j 1 x j B x; x j , x j 1 AL j 1 C x; x j , x j 1 xj x x j x j 1 x j 1 x j x j 1 x x j 1 x j 1 AL j (1.2) 2 1 3 A x; x j , x j 1 A x; x j , x j 1 x j 1 x j 6 2 1 D x; x j , x j 1 B 3 x; x j , x j 1 B x; x j , x j 1 x j 1 x j 6 With the definitions in (1.2), equation (1.1) is a cubic. It contains 4 adjustable linear coefficients yj, yj+1, y’’j, and y’’j+1. The first derivatives of (1.2) are A x; x j , x j 1 1 A' x x j 1 x j B x; x j , x j 1 x C x; x j , x j 1 x D x; x j , x j 1 A' B ' (1.3) 2 1 3 A2 1 A ' x j 1 x j 6 2 1 3B 2 1 B ' x j 1 x j x 6 So that the first derivative of (1.1) is y ' x A ' y j B ' y j 1 C ' y '' j D ' y '' j 1 (1.4) While the second derivatives are 2 A x; x j , x j 1 0 x 2 2 B x; x j , x j 1 0 x 2 (1.5) 2 C x; x j , x j 1 1 2 2 6 A A ' x j 1 x j A 2 6 x 2 D x; x j , x j 1 1 2 2 6 B B ' x j 1 x j B 2 6 x So that the second derivative of (1.1) is 1 Press, et al, Numerical Recipes (1986) section 3.3 y '' x A x; x j , x j 1 y '' j B x; x j , x j 1 y '' j 1 (1.6) The second derivatives are thus continuous and equal to the y’’ values for any set of y’’ values. The constraint is to make the first derivatives continuous. The required equations are obtained by setting (1.4) for x=xj in the interval (xj-1,xj) equal to the value in the interval (xj,xj+1). With some rearrangement, this gives for (j=2, …, N-1) x j x j 1 x j 1 x j 1 x j 1 x j y j 1 y j y j y j 1 y '' j 1 y '' j y '' j 1 (1.7) 6 3 6 x j 1 x j x j x j 1 This is a set of N-2 equations for the N unknown values of y’’. The natural boundary conditions are y’’1=y’’N=0. The set of equations is tri-diagonal making it solvable in order N operations. The third derivative of (1.1) is y '' j 1 y '' j y ''' x (1.8) x j 1 x j Bob thoughts Figure 1 There are four values of y'' in the above figure. The four values of y” are determined from the requirements that y’ at x1 and at x4 be equal to specified values and from the requirements that y’ at x2- equal y’ at x2+ and the same at x3. As a result of the above, we have lists {xi,yi,y’’i) from which the spline can be generated. The second derivative is given by the straight lines from y’’i to y’’i+1. The third derivative in each section is given by (y’’i+1 –y’’i)/(xi+1-xi). The third derivative has a discontinuity at each point xi. A spline can also be written as S x c j x j d j x x j 3 M j 0 j 1. 3 (2.1) Note that (2.1) has 4 + N undetermined constants that fit N yj values. This should be compared with (1.7) in which N 2 edge constraints are used to fit N yj values. This has derivatives S ' x c1 2c2 x 3c3 x 2 3 d j x x j (2.2) M 2 j 1. S '' x 2c2 3c3 x 6 d j x x j (2.3) M j 1. S ''' x 6c3 6 d j x x j M (2.4) j 1. Note that the derivative of the function is a delta function and the derivative of a delta function is steeper yet. At x1- Eqn (2.1) implies y1 c0 c1 x1 c2 x12 c3 x13 y1 ' c1 2c2 x1 3c3 x12 y1 '' 2c2 6c3 x1 y1 ''' 6c3 The only change at x1+ is that y1 ''' 6c3 6d1 The values from the splint method are assumed to be the same on both sides of x1 since these are a simple extrapolation out of the region. This implies that either d1 = 0 or that c3 = 0. If (1.8) is assumed to be the operational value on both sides of x1, then d1 must be zero. This same argument applies at xM. Thus the general equation (2.1) must be changed to 3 M 1 j 0 j 2. S x c j x j d j x x j (2.5) 3 As a practical fitting matter this implies that the first and last points in {xi} are not actually knots. That is y’’ values are determined for a point at the beginning and end of the region that are not knots.