import numpy as np from numpy import linalg m = cust_input.int_input(2, 10, "Enter the number of equations (from 2 to 10):\n") n = cust_input.int_input( 2, 10, "Enter the number of unknown variables (from 2 to 10):\n") A = np.zeros([m, n]) B = np.zeros([m, 1]) print("Enter coefficients next to unknown:\n") for i in range(m): for j in range(n): A[i, j] = cust_input.float_input( -1000000, 1000000, "Enter coefficient [%d, %d]:\n" % (i + 1, j + 1)) print("Enter free coefficients:\n") for i in range(m): B[i, 0] = cust_input.float_input(-1000000, 1000000, "Enter coefficient [%d]:\n" % (i + 1)) U, S, V = svd(A, m, n) mU = np.matrix(U) mB = np.matrix(B) mV = np.matrix(V.transpose()) K = mU * mB for i in range(min(m, n)):
n = cust_input.int_input( 2, 100, "Enter the number of function and variable values (from 2 to 100): \n") x = np.zeros(n) y = np.zeros(n) print("1 - custom input\n2 - random values\n") while 1: key = input() if key == '1' or key == '2': break if key == '1': for i in range(n): x[i] = cust_input.float_input( -1000000, 1000000, "Enter the %d value of variable: \n" % (i + 1)) y[i] = cust_input.float_input( -1000000, 1000000, "Enter the %d value of function: \n" % (i + 1)) elif key == '2': while 1: x_low = cust_input.float_input( -1000000, 1000000, "Enter the low border of values for variable (from -1000000 to 1000000):\n" ) x_high = cust_input.float_input( -1000000, 1000000, "Enter the high border of values for variable (from -1000000 to 1000000):\n" ) if x_high > x_low: break
Power = np.zeros([m]) # Power reserves Plan = np.zeros([n]) # Release plans X = np.zeros([m * n]) # Answer vector X_result = np.zeros([m, n]) # Answer matrix for i in range(m): for j in range(n): Prod[i, j] = cust_input.int_input( 1, 1000, "Enter the quantity of %d product %d machine per unit of time (from 1 to 1000): \n" % (j + 1, i + 1)) for i in range(m): for j in range(n): Cost[i, j] = cust_input.float_input( 0.01, 1000000, "Enter the cost price of %d product %d machine (from 0.01 to 1000000): \n" % (j + 1, i + 1)) for i in range(m): Power[i] = cust_input.int_input( 1, 1000000, "Enter the reserve of power for %d machine (from 1 to 1000000): \n" % (i + 1)) for j in range(n): Plan[j] = cust_input.float_input( 0.1, 1000000, "Enter the release plan of %d product (from 0.1 to 1000000): \n" % (j + 1)) objective_function = np.array([0])
import cust_input import numpy as np from hooke_jeeves_method import hooke_jeeves # variant 28: # f(x) = x1^2 + 16x2^2 n = 2 x0 = np.zeros([n]) print(x0) delta_x = np.zeros([n]) alpha = 2 print("Enter the starting point coordinates:\n") for i in range(n): x0[i] = cust_input.float_input(-1000000000, 1000000000, "Enter %d coordinate (from -1000000000 to 1000000000):\n" %(i+1)) epsilon = cust_input.float_input(0.0000000001, 1, "Enter accuracy (from 0.0000000001 to 1):\n") print("Enter step sizes:\n") for i in range(n): delta_x[i] = cust_input.float_input(0.00001, 1, "Enter step size for %d coordinate (from 0.00001 to 1):\n" %(i+1)) print("\nMinimum point: ", hooke_jeeves(x0, delta_x, epsilon, alpha))
import numpy as np from tridiagonal_matrix_method import tridiagonal_matrix n = cust_input.int_input(2, 100, "Enter matrix dimension (from 2 to 100):\n") a = np.zeros(n) b = np.zeros(n) c = np.zeros(n) d = np.zeros(n) print("Enter the elements of tridiagonal matrix:\n") for i in range(n): for j in range(n): if i == j + 1: a[i] = cust_input.float_input( -1000000, 1000000, "Enter element [%d, %d] (from -1000000 to 1000000):\n" % (i + 1, j + 1)) elif i == j: b[i] = cust_input.float_input( -1000000, 1000000, "Enter element [%d, %d] (from -1000000 to 1000000):\n" % (i + 1, j + 1)) elif j == i + 1: c[i] = cust_input.float_input( -1000000, 1000000, "Enter element [%d, %d] (from -1000000 to 1000000):\n" % (i + 1, j + 1)) print(a, b, c) print("Enter the vector of free coefficients:\n") for i in range(n):