Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scipy.interpolate import CubicSpline
- import matplotlib.pyplot as plt
- # Define the data points
- x = np.array([0.9, 1.3, 1.9, 2.1, 2.6, 3.0, 3.9, 4.4, 4.7, 5.0, 6.0, 7.0, 8.0, 9.2, 10.5, 11.3, 11.6, 12.0, 12.6, 13.0, 13.3])
- y = np.array([1.3, 1.5, 1.85, 2.1, 2.6, 2.7, 2.4, 2.15, 2.05, 2.1, 2.25, 2.3, 2.25, 1.95, 1.4, 0.9, 0.7, 0.6, 0.5, 0.4, 0.2])
- # Create the cubic spline object
- cs = CubicSpline(x, y, bc_type='natural')
- # Define the x-axis for plotting the curve
- xx = np.linspace(x.min(), x.max(), 1000)
- # Evaluate the cubic spline at the x-axis values
- yy = cs(xx)
- # Plot the original data points and the cubic spline curve
- plt.plot(x, y, 'o', label='Data Points')
- plt.plot(xx, yy, label='Cubic Spline')
- plt.xlabel('x')
- plt.ylabel('f(x)')
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement