Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.55 KB | None | 0 0
  1. class The_smallest_square():
  2.    
  3.     def __init__(self, tmp_list_value, tmp_function_value):
  4.         self.list_value = tmp_list_value
  5.         self.function_value = tmp_function_value
  6.        
  7.     def check_the_element_quantity(self):
  8.         if len(self.list_value) != len(self.function_value):
  9.             return False
  10.         return True
  11.    
  12.     def square_list_elements(self, list_to_make_square_values):
  13.         return [tmp_element**2 for tmp_element in list_to_make_square_values]
  14.    
  15.     def find_multiply_of_list(self, list_to_find_multiplication):
  16.         tmp_value = 1
  17.         for tmp_iterable in list_to_find_multiplication:
  18.             tmp_value *= tmp_iterable
  19.         return tmp_value
  20.    
  21.     def operate_with_direction_value(self, list_to_direction_value, list_of_value_to_multiply):
  22.         tmp_list = []
  23.         for tmp_iterable in list_of_value_to_multiply:
  24.             tmp_list.append(tmp_iterable*list_to_direction_value[0] + list_to_direction_value[1])
  25.         return tmp_list
  26.    
  27.     def linear_checking(self, first_list_to_check_linear, second_list_to_check_linear):
  28.         return self.find_multiply_of_list(first_list_to_check_linear) - self.find_multiply_of_list(second_list_to_check_linear)
  29.    
  30.     def krammer_solve(self, first_list_for_function, second_list_for_function, \
  31.                       first_list_for_value, second_list_for_value, determinant):
  32.         return [self.linear_checking(first_list_for_function, second_list_for_function)/determinant, \
  33.                self.linear_checking(first_list_for_value, second_list_for_value)/determinant]
  34.    
  35.     def multiply_lists(self, first_list_to_multiply, second_list_to_multiply):
  36.         return [first * second for first, second in zip(first_list_to_multiply, second_list_to_multiply)]
  37.    
  38.     def squares_calculation(self, first_list_to_square, second_list_to_square):
  39.         return sum([(first - second)**2 for first, second in zip(first_list_to_square, second_list_to_square)])
  40.    
  41.     def method(self):
  42.         if self.check_the_element_quantity() is not True:
  43.             print("Recheck your values, may you've missed one")
  44.             return 0
  45.    
  46.         list_with_function = [0, 0]
  47.         first_function_values = self.square_list_elements(self.list_value)
  48.         second_function_values = self.square_list_elements(self.function_value)
  49.         first_array_for_finding_self_value = [sum(first_function_values), len(self.function_value)]
  50.         second_array_for_finding_self_value = [sum(self.list_value)]*2
  51.        
  52.         first_krammar = [sum(self.multiply_lists(self.list_value, self.function_value)), len(self.list_value)]
  53.         second_krammar = [sum(self.list_value), sum(self.function_value)]
  54.         third_krammar = [sum(first_function_values), sum(self.function_value)]
  55.         fourth_krammar = [sum(self.multiply_lists(self.list_value, self.function_value)), sum(self.list_value)]
  56.         determinant = self.linear_checking(first_array_for_finding_self_value, second_array_for_finding_self_value)
  57.    
  58.         if determinant != 0:
  59.             list_with_function = self.krammer_solve(first_krammar, second_krammar, third_krammar, \
  60.                 fourth_krammar, determinant)
  61.         list_with_function = self.operate_with_direction_value(list_with_function, self.list_value)
  62.         return self.squares_calculation(list_with_function, self.function_value)
  63.  
  64. first_function_values = [0, 1, 2, 3, 4, 5]
  65. second_function_values = [2.2, 11.8, 26.4, 43.6, 66.8, 90.8]
  66.  
  67. a = The_smallest_square(first_function_values, second_function_values).method()
  68. print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement