Interpolation by splines¶
In the next presentation, we introduce splines and after that we present the simplest type of splines that are linear spline. Let's start with the already implemented functions from the scipy library. We will use the interpolate package. You can take a look for details ovaj link.
In [2]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
x=np.array([1 ,2 , 3, 4, 5 , 6])
y=np.array([16,18,21, 17, 15, 12])
y_linear = interp1d(x, y)
y_quadratic = interp1d(x, y, kind='quadratic')
y_cubic = interp1d(x, y, kind='cubic')
fig, ax = plt.subplots(figsize=(6.5, 4))
x2 = np.linspace(1, 6, 100)
plt.plot(x, y, 'o', label='data points')
plt.plot(x2, y_linear(x2), label='linear')
plt.plot(x2, y_quadratic(x2), label='quadratic')
plt.plot(x2, y_cubic(x2), label='cubic')
ax.legend(loc='upper right')
plt.savefig("splajn.eps")
In [3]:
from IPython.lib.display import YouTubeVideo
vid = YouTubeVideo("N4M_bLTR5j8")
display(vid)
Cubic spline¶
In [4]:
vid = YouTubeVideo("88TQI1kCRz0")
display(vid)
Excercises¶
In [5]:
vid = YouTubeVideo("roJyoK-bfpQ")
display(vid)
In [ ]: