2
我有非線性約束非線性函數,我想優化它。我不知道如何使用scipy.optimize定義非線性約束。我的代碼到目前爲止如下所示:scipy.optimize與非線性約束
from math import cos, atan
import numpy as np
from scipy.optimize import minimize
import sympy as sy
def f(x):
return 0.1*x*y
def ineq_constraint(x):
x**2 + y**2 - (5+2.2*sy.cos(10*sy.atan(x/y)))**2
return x,y
con = {'type': 'ineq', 'fun': ineq_constraint}
minimize(f,x0,method='SLSQP',constraints=con)
非常感謝! – user2702405
已經完成! :) – user2702405