最小化包含数组参数的函数

问题描述

我正在尝试最小化包含数组参数的函数

我试图在下面的例子中简化我的问题。函数 Func 包含参数 c2 = linspace(-1,1,10)。优化是关于 thet1、phai1、thet2 和 phai2,使它们受区间 (0,2*pi) 的约束。

import numpy as np
import scipy.optimize as spo

a1 = 0
c1 = 0
cc2 = np.linspace(-1,10)
alpha1 = 1+a1/3

def Func(ang):
    
    thet1 = ang[0]
    phai1 = ang[1]
    thet2 = ang[2]
    phai2 = ang[3]
    
    RhoABC = np.array([[[1-a1,thet1,c1],[0,alpha1,phai2,c2,0],thet2,phai1,thet2],[c1,1-a1]] for c2 in cc2])   
    w,v = np.linalg.eig(RhoABC)  
    return w[1]

angs0 = [.4*np.pi,1.9*np.pi,1.2*np.pi,.7*np.pi]

bnd = (0*np.pi,2*np.pi)
bnds = (bnd,bnd,bnd)

result = spo.minimize(Func,angs0,bounds=bnds) 

输出是: ValueError:轴太多:2(effrank=2),预期等级=1

我只想将最小值(乐趣)绘制为 c2 的函数。请问有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)