def splineInteg(x,y,integType): y2a = cubicSpline(x,y,integType) n = len(x) sum = 0 for i in range(n-1): h = x[i+1]-x[i] sum = sum + h*(y[i+1]+y[i])/2.0 sum = sum - h*h*h*(y2a[i+1]+y2a[i])/24.0 return sum
for i in range(3, 15): x = linspace(0, 15, 2 ** i) y = map(total_integ, x) ans = splineInteg(array(x), array(y), "knotanot") error.append(ANS - ans) figure(1) loglog(pow(2, array(range(3, 15))), abs(array(error)), "k") title("error vs no. of function calls") x = linspace(0, 10, 100) y = map(total_integ, x) xtest = linspace(0, 10, 500) x = array(x) y = array(y) xtest = array(xtest) y2a = cubicSpline(x, y, "knotanot") ytest = splintList(x, y, y2a, xtest) figure(2) title("spline interpolated function") semilogy(xtest, ytest, "k") x1 = linspace(0, 1, 64) y1 = map(total_integ, x1) tans = splineInteg(array(x1), array(y1), "knotanot") print tans error = [] for i in range(3, 15): x = linspace(1, 15, 2 ** i) y = map(total_integ, x) ans = splineInteg(array(x), array(y), "knotanot") error.append(ANS - ans[0] - tans) figure(1)