Question: please fill in missing code c) Write a program that demonstrates the Cubic Spline Curve Fitting method. You must write and call at least the

 please fill in missing code c) Write a program that demonstratesthe Cubic Spline Curve Fitting method. You must write and call atleast the following 3 functions: def CubicSpline (x, y, slope1=0, slope2=0): #calculatesand returns a matrix containing the coefficients of the cubic splines. slopel

please fill in missing code

c) Write a program that demonstrates the Cubic Spline Curve Fitting method. You must write and call at least the following 3 functions: def CubicSpline (x, y, slope1=0, slope2=0): #calculates and returns a matrix containing the coefficients of the cubic splines. slopel and slope2 are the slopes at the first and last points. def PlotCubicSpline (x, y, slopel, slope2, showpoints=True, npoints=500): #calls CubicSpline, generates data points and plots the cubic spline curve. If showpoints is True, also put the original data on the same plot. def main() : A main program that uses the data and slopes given below to: 1. Call CubicSpline to generate and print the coefficients. 2. Call plotCubicSpline to display a plot of the natural and clamped cubic splines as shown below. x=np: array([1.5, 3, 4.5, 6, 7.5, 9]) y=np. array([3.5, 1.5, -2, 6.9, 8.2,1.5]) slope1=2 slope 2=-4 natural clamped 8 6 4 Y values 2 --- 0 -2 import numpy as np import matplotlib.pyplot as pyplot from scipy import linalg def CubicSpline(x, y, slope1=0, slope2=0, Natural=True): I wrote this function to make a selection to use either Natural CubicSpline or ClampedCubicSpline depending on the boolean Natural. :param x: the x values at the nodes param y: the y values at the nodes param slope1: the slope of g(x) at leftmost node for clamped cubic spline :param slope2: the slope of g(x) at the rightmost node for clamped cubic spline :return: the result of either NaturalCubicSpline or ClampedCubicSpline return Natural CubicSpline(x,y) if Natural else ClampedCubicSpline(x,y, slope1, slope2) def ClampedCubicSpline(x,y, slopen, slope2): Given a set of data points (nodes) x,y and end point slopes, approximate f(x) with g(x), where g(x) is a cubic equation. We note that for each interval of x_(i)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!