Python program to returns the curvatures of cubic spline at its knots

''' k = curvatures(xData,yData).
    Returns the curvatures of cubic spline at its knots.
'''   
from numpy import zeros,ones
from LUdecomp3 import *
 
def curvatures(xData,yData):
    n = len(xData) - 1
    c = zeros(n)
    d = ones(n+1)
    e = zeros(n)
    k = zeros(n+1)
    c[0:n-1] = xData[0:n-1] - xData[1:n]
    d[1:n] = 2.0*(xData[0:n-1] - xData[2:n+1])
    e[1:n] = xData[1:n] - xData[2:n+1]
    k[1:n] =6.0*(yData[0:n-1] - yData[1:n]) \
                 /(xData[0:n-1] - xData[1:n]) \
             -6.0*(yData[1:n] - yData[2:n+1])   \
                 /(xData[1:n] - xData[2:n+1])
    LUdecomp3(c,d,e)
    LUsolve3(c,d,e,k)
    return k

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.