我试着最小化函数
B1=0.00299540627439527*x[0]**2 + 0.00701825276534463*x[0]*x[1] + 0.0672877782113971*x[0] + 0.00456646480250456*x[1]**2 + 0.054080834634827*x[1] + 0.298938755491431
在x1=[-10,10]
和x2=[-10,10]
的状态空间上
给出下面的不等式约束
EqX0=[[(x[0]+5)**2+x[1]**2-2.5]]<=0
其中x[0]
和{x1
和{
ga=1
是一个参数
然而,当我使用SLSQP来求解非线性约束优化问题时,答案是x=[-10,10],它不满足不等式约束。在
下面是一段代码:
def Objective2(ax):
B2=B1.copy()
B2=B2.subs((x[i],ax[i]) for i in range(len(ax)))
return ga-B2
def Constraint1(ax):
EqX0c=EqX0.copy()
cc=[]
for pp in range(len(EqX0c)):
cc.append(-EqX0c[0][pp].subs((x[i],ax[i]) for i in range(len(ax))))
return cc
con1= {'type': 'ineq','fun': Constraint1}
bounds=Bounds([-10,10],[-10,10])
sol2=minimize(Objective2,x0,method="SLSQP",bounds=bounds,constraints=con1)
这是产出。程序成功终止,但给出错误的结果。在
fun: -0.12123115088124994
jac: array([-0.07756218, -0.0752276 ])
message: 'Optimization terminated successfully.'
nfev: 4
nit: 5
njev: 1
status: 0
success: True
x: array([-10., 10.])
我怎么能解决这个问题呢?在
我认为你定义的界限有误。尝试
Bounds([-10,-10],[10,10])
。在参见docs。在
相关问题 更多 >
编程相关推荐