Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. import random
  2. import numpy as np
  3. import scipy.interpolate as sp
  4. import matplotlib.pyplot as plt
  5. from scipy import interpolate
  6.  
  7. class Spline_Interpolation():
  8.     def __init__(self):
  9.         self.x_points = [2, 3, 4, 7]
  10.         self.y_points = [2, 1, 3, 8]
  11.         self.derivative_1 = -2
  12.         self.derivative_2 = 2
  13.  
  14.     def plot_the_graph(self, list_with_x, list_with_y):
  15.         pass
  16.  
  17.     def calculate_the_h_delta(self):
  18.         list_h = [self.x_points[iterable] - self.x_points[iterable - 1] for iterable in range(1, len(self.x_points), 1)]
  19.         list_delta = [(self.y_points[iterable] - self.y_points[iterable - 1])/list_h[iterable - 1] for iterable in range(1, len(self.y_points), 1)]
  20.         #print(list_h, '\n', list_delta)
  21.         return list_h, list_delta
  22.  
  23.     def calculate_the_list(self):
  24.         list_h, list_delta = self.calculate_the_h_delta()
  25.         list_of_unsolved_equations = [[] for tmp in range(0, len(self.y_points),1)]
  26.         for tmp_rows in range(0, len(list_of_unsolved_equations),1):
  27.             for tmp_columns in range(0, len(list_of_unsolved_equations),1):
  28.                 if 0 < (tmp_rows == tmp_columns) < len(list_of_unsolved_equations) :
  29.                     list_of_unsolved_equations[tmp_rows][tmp_columns].append(list_h[tmp_rows] + list_h[tmp_rows + 1])
  30.                 elif tmp_rows == tmp_columns == 0:
  31.                     list_of_unsolved_equations[tmp_rows][tmp_columns].append(2*list_h[tmp_rows])
  32.                 elif tmp_rows == tmp_columns == len(list_of_unsolved_equations) - 1:
  33.                     list_of_unsolved_equations[tmp_rows][tmp_columns].append(2*list_h[len(list_h) - 1])
  34.                 elif (tmp_rows - tmp_columns) == 1:
  35.                     list_of_unsolved_equations[tmp_rows][tmp_columns].append(list_h[tmp_rows])
  36.                     list_of_unsolved_equations[tmp_columns][tmp_rows].append(list_h[tmp_rows])
  37.                 else:
  38.                     list_of_unsolved_equations[tmp_columns][tmp_rows].append(0)
  39.         print(list_of_unsolved_equations)
  40.         return 0
  41.  
  42. a = Spline_Interpolation().calculate_the_list()
  43.  
  44.  
  45. def calculate():
  46.     x_points = [ 2, 3, 4, 7]
  47.     y_points = [ 2, 1, 3, 8]    
  48.     cs = interpolate.CubicSpline(x_points, y_points, bc_type = ((1, -2), (1, 2)))
  49.     xnew=np.linspace(np.min(x_points),np.max(x_points),100)
  50.     ynew=cs(xnew)
  51.     plt.plot(xnew,ynew, label = 'S')
  52.     plt.plot(xnew,cs(xnew,1), label = 'S\'')
  53.     plt.plot(x_points, y_points, 'o');
  54.     plt.show();
  55. #a = calculate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement