def find(self, n): # not possible if n <= 1 or not n & 1: return False if n <= self.config["BIGGEST_ONES"][-1]: # we find the segment c = self.find_segment(n) if type(c) is tuple: # we use the dichotomy algo to frame the prime number seg = 0 if c == (0, -1) else c[-1] c = dichotomy.dichotomy(self.get(seg), n) if isinstance(c, tuple): return False else: return c + self.SEGMENT_SIZE * seg else: return (c + 1) * self.SEGMENT_SIZE - 1 else: return False
def main(): input_is_enabled = False for i in range(1, len(sys.argv)): if sys.argv[i] == '--input': input_is_enabled = True if input_is_enabled: input_data() else: print_data() p = dt.dichotomy(3, 25, F, EPSILON) print("P = %g"%(p))
def Nt(t, p): X = [-1, 3, -1, -10, -20, -35] dX = [0] * len(X) dx_x = 1 while dx_x >= EPSILON: for i in range(len(X)): X[i] += dX[i] gamma = dt.dichotomy(0, 3, lambda g: Gamma(g, t, X), EPSILON) k = K(t, gamma) alpha = 0.285 * 10**-11 * (gamma * t)**3 expV = math.exp(X[0]) expX1 = math.exp(X[1]) expX2 = math.exp(X[2]) expX3 = math.exp(X[3]) expX4 = math.exp(X[4]) expX5 = math.exp(X[5]) lnK0 = math.log(k[0]) lnK1 = math.log(k[1]) lnK2 = math.log(k[2]) lnK3 = math.log(k[3]) z_right = Z[1]*expX2 + Z[2]*expX3 + Z[3]*expX4 + Z[4]*expX5 - expV a_right = expV + expX1 + expX2 + expX3 + expX4 + expX5 - alpha - p*7243/t; eqsystem = [ [ 1, -1, 1, 0, 0, 0, lnK0 + X[1] - X[2] - X[0]], [ 1, 0, -1, 1, 0, 0, lnK1 + X[2] - X[3] - X[0]], [ 1, 0, 0, -1, 1, 0, lnK2 + X[3] - X[4] - X[0]], [ 1, 0, 0, 0, -1, 1, lnK3 + X[4] - X[5] - X[0]], [ expV, -Z[0]*expX1, -Z[1]*expX2, -Z[2]*expX3, -Z[3]*expX4, -Z[4]*expX5, z_right], [ -expV, -expX1, -expX2, -expX3, -expX4, -expX5, a_right] ] dX = gs.gauss(eqsystem) dx_x = max([ (dX[i] / X[i]) for i in range(len(X)) ]) return sum([math.exp(x) for x in X])
def Nt(T, P): X = [-1, 3, -1, -10, -20, -35] while True: gamma = dichotomy(0, 3, EPS, lambda cur_gamma: gamma_func(cur_gamma, T, X)) d_e = find_d_e(T, gamma) K = find_K(T, d_e) alpha = 0.285 * pow(10, -11) * pow(gamma * T, 3) system = [[1, -1, 1, 0, 0, 0, log(K[0]) + X[1] - X[2] - X[0]], [1, 0, -1, 1, 0, 0, log(K[1]) + X[2] - X[3] - X[0]], [1, 0, 0, -1, 1, 0, log(K[2]) + X[3] - X[4] - X[0]], [1, 0, 0, 0, -1, 1, log(K[3]) + X[4] - X[5] - X[0]], [ -exp(X[0]), -exp(X[1]), -exp(X[2]), -exp(X[3]), -exp(X[4]), -exp(X[5]), exp(X[0]) + exp(X[1]) + exp(X[2]) + exp(X[3]) + exp(X[4]) + exp(X[5]) - alpha - P * 7243 / T ], [ exp(X[0]), 0, -Z_c[1] * exp(X[2]), -Z_c[2] * exp(X[3]), -Z_c[3] * exp(X[4]), -Z_c[4] * exp(X[5]), Z_c[1] * exp(X[2]) + Z_c[2] * exp(X[3]) + Z_c[3] * exp(X[4]) + Z_c[4] * exp(X[5]) - exp(X[0]) ]] d_X = Gauss(system) if max([d_X[i] / X[i] for i in range(len(X))]) < 1e-4: break for i in range(len(X)): X[i] += d_X[i] return sum([exp(i) for i in X])
from swenn import swenn from dichotomy import dichotomy from fibonacci import fibonacci from golden_ratio import golden_ratio A = 7 X0 = 5.5 E = 0.2 DELTA = 0.1 def o_my_work_function(x): return x**2 - A * x interval = swenn(o_my_work_function, X0, DELTA) print('result swen', interval) print('result dichotomy', dichotomy(o_my_work_function, interval[0], interval[1], E)) print('result fibonacci', fibonacci(o_my_work_function, interval[0], interval[1], 15)) print('result golden', golden_ratio(o_my_work_function, interval[0], interval[1], 0.1))
-Z_c[3] * exp(X[4]), -Z_c[4] * exp(X[5]), Z_c[1] * exp(X[2]) + Z_c[2] * exp(X[3]) + Z_c[3] * exp(X[4]) + Z_c[4] * exp(X[5]) - exp(X[0]) ]] d_X = Gauss(system) if max([d_X[i] / X[i] for i in range(len(X))]) < 1e-4: break for i in range(len(X)): X[i] += d_X[i] return sum([exp(i) for i in X]) Pn = 0.5 #float(input("Pнач: ")) Tn = 300 #float(input("Tнач: ") T0 = 12000 #float(input("T0: ")) Tw = 6000 #float(input("Tw: ")) m = 12 #float(input("m: ")) coeff = 7243 * (Pn / Tn) if __name__ == '__main__': a = time() res_p = dichotomy(2, 25, EPS, F) b = time() print("Result: ", res_p) t = b - a
def find_segment(self, n): if n <= self.config["BIGGEST_ONES"][-1]: return dichotomy.dichotomy(self.config["BIGGEST_ONES"], n) else: return False