Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import numpy as np
- import scipy.interpolate as sp
- import matplotlib.pyplot as plt
- from scipy import interpolate
- class Spline_Interpolation():
- def __init__(self):
- self.x_points = [2, 3, 4, 7]
- self.y_points = [2, 1, 3, 8]
- self.derivative_1 = -2
- self.derivative_2 = 2
- def plot_the_graph(self, list_with_x, list_with_y):
- pass
- def calculate_the_h_delta(self):
- list_h = [self.x_points[iterable] - self.x_points[iterable - 1] for iterable in range(1, len(self.x_points), 1)]
- 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)]
- #print(list_h, '\n', list_delta)
- return list_h, list_delta
- def calculate_the_list(self):
- list_h, list_delta = self.calculate_the_h_delta()
- list_of_unsolved_equations = [[] for tmp in range(0, len(self.y_points),1)]
- for tmp_rows in range(0, len(list_of_unsolved_equations),1):
- for tmp_columns in range(0, len(list_of_unsolved_equations),1):
- if 0 < (tmp_rows == tmp_columns) < len(list_of_unsolved_equations) :
- list_of_unsolved_equations[tmp_rows][tmp_columns].append(list_h[tmp_rows] + list_h[tmp_rows + 1])
- elif tmp_rows == tmp_columns == 0:
- list_of_unsolved_equations[tmp_rows][tmp_columns].append(2*list_h[tmp_rows])
- elif tmp_rows == tmp_columns == len(list_of_unsolved_equations) - 1:
- list_of_unsolved_equations[tmp_rows][tmp_columns].append(2*list_h[len(list_h) - 1])
- elif (tmp_rows - tmp_columns) == 1:
- list_of_unsolved_equations[tmp_rows][tmp_columns].append(list_h[tmp_rows])
- list_of_unsolved_equations[tmp_columns][tmp_rows].append(list_h[tmp_rows])
- else:
- list_of_unsolved_equations[tmp_columns][tmp_rows].append(0)
- print(list_of_unsolved_equations)
- return 0
- a = Spline_Interpolation().calculate_the_list()
- def calculate():
- x_points = [ 2, 3, 4, 7]
- y_points = [ 2, 1, 3, 8]
- cs = interpolate.CubicSpline(x_points, y_points, bc_type = ((1, -2), (1, 2)))
- xnew=np.linspace(np.min(x_points),np.max(x_points),100)
- ynew=cs(xnew)
- plt.plot(xnew,ynew, label = 'S')
- plt.plot(xnew,cs(xnew,1), label = 'S\'')
- plt.plot(x_points, y_points, 'o');
- plt.show();
- #a = calculate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement