python - 从最小化中排除一些参数
问题描述
如果我有一个函数,我可以使用排除优化过程func(x1,x2,x3)
的最小化函数 ,其中定义为。在这种情况下如何定义论点?我应该得到一个数组,其中包含 的每个值的最小值。scipy.optimize.minimize
x3
x3
numpy array
func
x3
例如:
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)
解决方案
也许你可以使用这样的东西:
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.
推荐阅读
- google-cloud-platform - 在 terraform 中使用“google_identity_platform_oauth_idp_config”时如何设置“授权类型”?
- mysql - 让 MySQL 使用索引类型“唯一”和索引类型“索引”作为查询的键
- php - 如何设置我的服务器以使用 PHP
- c++ - 如何通过用户输入添加此 URL 的路径?
- neo4j - 如何提高我在 Neo4j 中的 count() 查询的性能?
- java - 房间表之间的关系 Android
- google-bigquery - 控制 AVRO 文件的数量
- vba - 使用vba下载图像时如何解决错误?
- powershell - 如何创建一个 powershell 脚本来删除它所在的目录?
- 3d - 一种在MeshLab中创建点云数据横截面视图的方法