Advertisement
rfq

flying bird natural cubic spline

rfq
May 10th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import numpy as np
  2. from scipy.interpolate import CubicSpline
  3. import matplotlib.pyplot as plt
  4.  
  5. # Define the data points
  6. 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])
  7. 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])
  8.  
  9. # Create the cubic spline object
  10. cs = CubicSpline(x, y, bc_type='natural')
  11.  
  12. # Define the x-axis for plotting the curve
  13. xx = np.linspace(x.min(), x.max(), 1000)
  14.  
  15. # Evaluate the cubic spline at the x-axis values
  16. yy = cs(xx)
  17.  
  18. # Plot the original data points and the cubic spline curve
  19. plt.plot(x, y, 'o', label='Data Points')
  20. plt.plot(xx, yy, label='Cubic Spline')
  21. plt.xlabel('x')
  22. plt.ylabel('f(x)')
  23. plt.legend()
  24. plt.show()
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement