Question: Complete the Python function MySpline that reads in a set of x and y values (each as arrays or lists), and outputs a piecewise-cubic
Complete the Python function MySpline that reads in a set of x and y values (each as arrays or lists), and outputs a piecewise-cubic function with natural boundary conditions. The function prototype is cs = MySpline (x, y) The returned function can be called using cs (2.4) or cs ([2.4, 3.7]), for example. You will have to find the parameter values for the as, bs, and cs so that the cubic spline can be evaluated using (x+1-x) 6h pi(z)= a-11 + ai + bx (x+1x) + C (x - x), 6h where h = +1 - and i = 1,2,...,n 1. Note that all Python indexing starts at 0, so all the indices can be decremented by 1. However, some care is needed to handle ao,... an-1. See the documentation for MySpline for some guidance on this issue. The function MySpline is already set up to return a cubic spline function. But it's not a very interesting one, and it does not pass through the points (ri, Yi). The notebook has a small sample set of points to interpolate. Feel free to choose your own set of points. Create a figure that plots the interpolation points overtop of the smooth cubic spline.
Step by Step Solution
3.42 Rating (149 Votes )
There are 3 Steps involved in it
plementing cubic spline interpolation and plotting the results Heres a general outline of the steps you can follow Define the function MySplinex y tha... View full answer
Get step-by-step solutions from verified subject matter experts
