## example5_4
# Given the data
#   x  1.5    1.9    2.1    2.4    2.6    3.1
# f(x) 1.0628 1.3961 1.5432 1.7349 1.8423 2.0397
# compute f'(2) and f''(2) using a natural cubic spline interpolant spanning 
# all the data points
# Solution: We must first determine the second derivatives ki of the spline
# at its knots, after which the derivatives of f(x) can be computed from
# Eqs. (5.10) and (5.11)
from cubicSpline import curvatures
from LUdecomp3 import *
import numpy as np
xData = np.array([1.5,1.9,2.1,2.4,2.6,3.1])
yData = np.array([1.0628,1.3961,1.5432,1.7349,1.8423, 2.0397])
print(curvatures(xData,yData))
input("Press return to exit")


Because x = 2 lies between knots 1 and 2, we must use the following Eqs. with i = 1: $$f_{i,i+1}^{'}(x)=\frac{k_{i}}{6}\left [ \frac{3(x-x_{i+1})^{2}}{x_{i}-x_{i+1}} -(x_{i}-x_{i+1})\right ]- \frac{k_{i+1}}{6}\left [ \frac{3(x-x_{i})^{2}}{x_{i}-x_{i+1}} -(x_{i}-x_{i+1})\right ]+\frac{y_{i}-y_{i+1}}{x_{i}-x_{i+1}}$$ $$f_{i,i+1}^{''}(x)=k_{i}\frac{x-x_{i+1}}{x_{i}-x_{i+1}} - k_{i+1}\frac{x-x_{i}}{x_{i}-x_{i+1}}$$