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
| from sympy import Symbol, symbols, solve from scipy.optimize import minimize_scalar
a, b, c = symbols(("a", "b", "c")) eq1 = a + b + c - 10 eq2 = 4*a + 2*b + c - 18 eq3 = 9*a + 3*b + c - 19 ans = solve((eq1, eq2, eq3)) print(ans)
def f(x, a, b, c) : return (a*x**2 + b*x + c) def g(x, a, b, c) : return -f(x, a, b, c)
print(ans[a].evalf(), ans[b].evalf(), ans[c].evalf())
args = (float(ans[a].evalf()), float(ans[b].evalf()), float(ans[c].evalf())) peak = minimize_scalar(g, args=args) limit_y = -peak.fun print(f"max ({peak.x},{limit_y})")
|