1 2 3 4 5 6 7 8 9 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
| import numpy as np from scipy.optimize import nnls
def calculate_styx(B, H, e): n=B m=H-n
if n< 3: t = 0 s = n - e / 2 x = m - n + e / 2 y = n - m / 2 else: M = np.array([ [1, 0, 0, 1], [1, 2, 2, 1], [4, 6, 4, 2] ])
Bond = np.array([m, 2 * n + e, 6 * n])
solution, _ = nnls(M, Bond)
s, t, y, x = np.round(solution).astype(int)
if all(param >= 0 for param in [s, t, y, x]): return {"s": s, "t": t, "y": y, "x": x}
return "No valid STYX parameters found."
calculate_styx(4, 4, 2)
|