- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
def approximate_input(to_reach, error, constants, variable, formula, goes_down, default_value=0, RPV=0, var_max=0, fun_RPV=0, fun_min=0):
var = default_value
dvar = 1
dm = 0
current_vars = constants
current_vars[variable] = var
fx = eval(formula, globals(), current_vars)
while 1:
delta_var = var
if (abs(fx-to_reach) <= error):
return var
if (fx < to_reach and not goes_down):
if (dm==2):
dvar = dvar / 2
dm = 1
if (RPV and var+dvar > var_max):
var = var - dvar
else:
var = var + dvar
current_vars[variable] = var
elif (fx > to_reach and goes_down):
if (dm==2):
dvar = dvar / 2
dm = 1
if (RPV and var+dvar > var_max):
var = var - dvar
else:
var = var + dvar
current_vars[variable] = var
elif (fx > to_reach and not goes_down):
if (dm==1):
dvar = dvar / 2
dm = 2
if (RPV and var+dvar > var_max):
var = var + dvar
else:
var = var - dvar
current_vars[variable] = var
elif (fx < to_reach and goes_down):
if (dm==1):
dvar = dvar / 2
dm = 2
if (RPV and var+dvar > var_max):
var = var + dvar
else:
var = var - dvar
current_vars[variable] = var
fx = eval(formula, globals(), current_vars)
delta_var = delta_var - var
delta_var = var - delta_var
if (fun_RPV):
if (fx < fun_min):
var = var + delta_var
Как один мудак на питоне писал симулятор баллистического полета с учетом ламинарного сопротивления среды
EditorRUS 11.06.2015 10:17 # 0
А вот так вот оно используется:
Stertor 11.06.2015 10:23 # 0
EditorRUS 11.06.2015 10:26 # 0
Stertor 11.06.2015 10:43 # 0