# Cubic spline interpolation
from scipy.interpolate import CubicSpline
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("seaborn-poster")
x = [0, 1, 2]
y = [1, 3, 2]
# use bc_type = "natural" adds the constraints
f = CubicSpline(x, y, bc_type="natural")
x_new = np.linspace(0, 2, 100)
y_new = f(x_new)
my_dpi=100
plt.figure(figsize = (510/my_dpi,287/my_dpi),dpi=my_dpi)
plt.plot(x_new, y_new, "b")
plt.plot(x, y, "ro")
plt.title("Cubic Spline Interpolation")
plt.xlabel("x")
plt.ylabel("y")
plt.savefig('ex199.png', dpi=my_dpi)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading