def solve_eq(inp): from web_app_tool import final_step result, matrix = final_step(inp) def abs(lis): if lis < 0: lis = lis * -1 return lis for k in range(len(result)): if abs(matrix[k][k]) < 0: for i in range(k + 1, len(result)): if abs(matrix[i][k]) > abs(matrix[k][k]): for j in range(k, len(result)): matrix[k][j], matrix[i][j] = matrix[i][j], matrix[k][j] result[k], result[i] = result[i], result[k] break pivot = matrix[k][k] for j in range(k, len(result)): matrix[k][j] /= pivot result[k] /= pivot for i in range(len(result)): if i == k or matrix[i][k] == 0: continue factore = matrix[i][k] for j in range(k, len(result)): matrix[i][j] -= factore * matrix[k][j] result[i] -= factore * result[k] return matrix, result
def angle(vec): import math from web_app_tool import final_step vector_1, vector_2 = final_step(vec) def dot_product(vector_1, vector_2): dot_product = 0 for index in range(len(vector_1)): try: dot_product += vector_1[index] * vector_2[index] except IndexError: "" return dot_product def absolute_value(vector): import math val = 0 for element in vector: val += element**2 return math.sqrt(val) result = math.acos( dot_product(vector_2, vector_1) / (absolute_value(vector_2) * absolute_value(vector_1))) return math.degrees(result)
def finde_position_vector(vec): from web_app_tool import final_step point_1, point_2 = final_step(vec) for element in range(len(point_1)): point_2[element] = point_2[element] - point_1[element] return point_2
def vector_addition(vec): from web_app_tool import final_step vector_1, vector_2 = final_step(vec) for element in range(len(vector_2)): try: vector_1[element] += vector_2[element] except IndexError: vector_1.append(vector_2[element]) return vector_1
def cross_product(vec): from web_app_tool import final_step vector_1, vector_2 = final_step(vec) new_vector = [1, 1, 1] new_vector[0] *= vector_1[1] * vector_2[2] - vector_1[2] * vector_2[1] new_vector[1] *= vector_1[2] * vector_2[0] - vector_1[0] * vector_2[2] new_vector[2] *= vector_1[0] * vector_2[1] - vector_1[1] * vector_2[0] return new_vector
def dot_product(vec): from web_app_tool import final_step vector_1, vector_2 = final_step(vec) dot_product = 0 for index in range(len(vector_1)): try: dot_product += vector_1[index] * vector_2[index] except IndexError: "" return dot_product
def MM_multiplication(vec): #needs square matrix from web_app_tool import final_step matrix_1, matrix_2 = final_step(vec) end_matrix = [] for element in range(len(matrix_1)): end_matrix.append([]) for none in matrix_1: end_matrix[element].append(0) for i in range(len(matrix_1)): for j in range(len(matrix_1)): for k in range(len(matrix_1)): end_matrix[i][j] += matrix_1[i][k] * matrix_2[k][j] return end_matrix
def VM_multiplication(inp): from web_app_tool import final_step vector, matrix = final_step(inp) for element in range(len(vector)): try: for collum in range(len(matrix[element])): matrix[element][ collum] = matrix[element][collum] * vector[element] except IndexError: "" for new in range(len(vector)): vector[new] = 0 try: for col in range(len(matrix)): vector[new] += matrix[col][new] except IndexError: "" return vector