December 2017
Intermediate to advanced
386 pages
10h 42m
English
Here, we construct a quadratic spline function on the base interval 2 <= x <= 4 and compare it with the naive way of evaluating the spline:
from scipy import interpolateimport numpy as npimport matplotlib.pyplot as plt# samplingx = np.linspace(0, 10, 10)y = np.sin(x)# spline trough all the sampled pointstck = interpolate.splrep(x, y)x2 = np.linspace(0, 10, 200)y2 = interpolate.splev(x2, tck)# spline with all the middle points as knots (not working yet)# knots = x[1:-1] # it should be something like thisknots = np.array([x[1]]) # not working with above line and just seeing what this line doesweights = np.concatenate(([1],np.ones(x.shape[0]-2)*.01,[1]))tck = interpolate.splrep(x, y, t=knots, w=weights)x3 = np.linspace(0, 10, ...
Read now
Unlock full access