Python optimization using sympy lambdify and scipy
问题 I'm trying to maximize a function defined by sympy but cannot make it work. The basic idea can be summarized as follows: import sympy from scipy.optimize import minimize from sympy.utilities.lambdify import lambdify a,b,G = sympy.symbols('a b G') func = (G - a)**2 + b my_func = lambdify((G,a,b), -1*func) results = minimize(my_func,[0.1,0.1,0.1]) The code works if I define a single-variable function, but as long as I have more than one variable, I receive the following error message. TypeError