首页 > 解决方案 > 从最小化中排除一些参数

问题描述

如果我有一个函数,我可以使用排除优化过程func(x1,x2,x3)的最小化函数 ,其中定义为。在这种情况下如何定义论点?我应该得到一个数组,其中包含 的每个值的最小值。scipy.optimize.minimizex3x3numpy arrayfuncx3

例如:

def func(thet1,phai1,thet2,phai2,c2):
    
    RhoABC = np.array([[1,0,thet1,0,0,0,0,c1],[0,1,0,0,phai2,0,c2,0],[0,0,1,0,0,c2,thet2,0],[0,0,0,1,c2,0,0,0],[0,phai1,0,c2,1,0,0,0],[0,0,c2,0,0,1,0,thet2],[0,c2,0,0,0,0,1,0],[c1,0,0,phai1,0,0,0,1]])   
    w, v = np.linalg.eig(RhoABC)  
    return w[1] 

我想将它最小化在哪里c2 = linspace(-1,1,10)和角度属于(0,2pi)

标签: pythonscipy-optimize-minimize

解决方案


也许你可以使用这样的东西:

def func(thet1,phai1,thet2,phai2,*args, c2 = []):
#considering c2 to be x3 in the above post
    
    RhoABC = np.array([[1,0,thet1,0,0,0,0,c1],[0,1,0,0,phai2,0,c2,0],[0,0,1,0,0,c2,thet2,0],[0,0,0,1,c2,0,0,0],[0,phai1,0,c2,1,0,0,0],[0,0,c2,0,0,1,0,thet2],[0,c2,0,0,0,0,1,0],[c1,0,0,phai1,0,0,0,1]])   
    w, v = np.linalg.eig(RhoABC)  
    return w[1] 

然后当你调用函数时:

retVal = func(thet1,phai1,thet2,phai2, c2=c2)

#you have to specify c2 first and then equate it to the value since this is an optional argument.

推荐阅读