What's brown and sticky?
A stick.
Wanna hear a joke about paper?
Never mind-it's tearable.
\[ \begin{aligned} p_1(x) &= a_1 x^3 + b_1 x^2 + c_1 x + d_1 , \,\, 1 \leq x \leq 2 \\ p_2(x) &= a_2 x^3 + b_2 x^2 + c_2 x + d_2 , \,\, 2 \leq x \leq 3 \end{aligned} \]
Find a spline approximation and a polynomial approximation for the curve of the cross section of the circular shaped Shrine of the Book in Jerusalem.
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
#Enter data
x = [-5.8, -5.0, -4.0, -2.5, -1.5, -0.8, 0, 0.8, 1.5, 2.5, 4.0, 5.0, 5.8]
y = [0, 1.5, 1.8, 2.2, 2.7, 3.5, 3.9, 3.5, 2.7, 2.2, 1.8, 1.5, 0]
#Command for cubic spline spline polynomial p(x)
p = interp1d(x, y, kind = 'cubic')
#Create vector of 500 points between 0 and x[n-1] on x-axis
n = len(x)
xnew = np.linspace(x[0], x[n-1], num=500, endpoint=True)
#Plot the original data together with p(x) sampled at the 500 points
plt.plot(x, y, 'o', xnew, p(xnew), '-,r')
plt.legend(['Original Data','Cubic Spline p(x)'], loc = 'best')
plt.show()