Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class The_smallest_square():
- def __init__(self, tmp_list_value, tmp_function_value):
- self.list_value = tmp_list_value
- self.function_value = tmp_function_value
- def check_the_element_quantity(self):
- if len(self.list_value) != len(self.function_value):
- return False
- return True
- def square_list_elements(self, list_to_make_square_values):
- return [tmp_element**2 for tmp_element in list_to_make_square_values]
- def find_multiply_of_list(self, list_to_find_multiplication):
- tmp_value = 1
- for tmp_iterable in list_to_find_multiplication:
- tmp_value *= tmp_iterable
- return tmp_value
- def operate_with_direction_value(self, list_to_direction_value, list_of_value_to_multiply):
- tmp_list = []
- for tmp_iterable in list_of_value_to_multiply:
- tmp_list.append(tmp_iterable*list_to_direction_value[0] + list_to_direction_value[1])
- return tmp_list
- def linear_checking(self, first_list_to_check_linear, second_list_to_check_linear):
- return self.find_multiply_of_list(first_list_to_check_linear) - self.find_multiply_of_list(second_list_to_check_linear)
- def krammer_solve(self, first_list_for_function, second_list_for_function, \
- first_list_for_value, second_list_for_value, determinant):
- return [self.linear_checking(first_list_for_function, second_list_for_function)/determinant, \
- self.linear_checking(first_list_for_value, second_list_for_value)/determinant]
- def multiply_lists(self, first_list_to_multiply, second_list_to_multiply):
- return [first * second for first, second in zip(first_list_to_multiply, second_list_to_multiply)]
- def squares_calculation(self, first_list_to_square, second_list_to_square):
- return sum([(first - second)**2 for first, second in zip(first_list_to_square, second_list_to_square)])
- def method(self):
- if self.check_the_element_quantity() is not True:
- print("Recheck your values, may you've missed one")
- return 0
- list_with_function = [0, 0]
- first_function_values = self.square_list_elements(self.list_value)
- second_function_values = self.square_list_elements(self.function_value)
- first_array_for_finding_self_value = [sum(first_function_values), len(self.function_value)]
- second_array_for_finding_self_value = [sum(self.list_value)]*2
- first_krammar = [sum(self.multiply_lists(self.list_value, self.function_value)), len(self.list_value)]
- second_krammar = [sum(self.list_value), sum(self.function_value)]
- third_krammar = [sum(first_function_values), sum(self.function_value)]
- fourth_krammar = [sum(self.multiply_lists(self.list_value, self.function_value)), sum(self.list_value)]
- determinant = self.linear_checking(first_array_for_finding_self_value, second_array_for_finding_self_value)
- if determinant != 0:
- list_with_function = self.krammer_solve(first_krammar, second_krammar, third_krammar, \
- fourth_krammar, determinant)
- list_with_function = self.operate_with_direction_value(list_with_function, self.list_value)
- return self.squares_calculation(list_with_function, self.function_value)
- first_function_values = [0, 1, 2, 3, 4, 5]
- second_function_values = [2.2, 11.8, 26.4, 43.6, 66.8, 90.8]
- a = The_smallest_square(first_function_values, second_function_values).method()
- print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement