
228 Introduction to Computational Models with Python
Figure 16.4 Graph of given data points.
5
6 y = [-310.0, -179.8, -82.3, -13.6, 30.0, 52.6,57.8, 49.6,
31.8, 8.2, -17.2,-40.8, -58.6, -66.8, -61.5,-39.0, 4.6,
73.3, 170.8, 301.0]
7 y = np.array(y)
8 N = np.size(y)
9 xi = -6.0
10 xf = 7.0
11 x = np.linspace(xi, xf, N)
12 sprep = interpolate.splrep(x, y, s=0) # spline of y
13 M = int(1.5 * N) # more points
14 xint = np.linspace(xi, xf, M)
15 yint = interpolate.splev(xint, sprep, der=0) # interp
16 print "Cubic Spline interpolation:"
17 for j in range(M):
18 print xint[j], yint[j]
Figure 16.4 shows the graph of original data points that define a curve.
Figure