G = []
while iPhase < len(f): # loop through all free energy functions
G.append(f[iPhase](x)) # x is an array of x values
iPhase = iPhase+1
minG = G{0][:] # define an overall minimum free energy curve, starting with 0'th
minF = np.zeros(len(minG)) # prepare for index indicating which function f[i](x) is min
iPhase = 1
while iPhase < len(f):
nextF = iPhase*np.ones(len(x0, dtype=np.int)
np.less(G[iPhase],minG, nextF) # where is next free energy function less than current min
minG = np.minimum(minG, G[iPhase]) # new overall minimum
minF = np.ma.filled(np.ma.array(minF, mask=nextF), fill_value=iPhase) # new index as needed
iPhase = iPhase+1
像这样:
假设您有以下列表:
您可以通过以下方法获得每个数组的最小值:
抱歉,我不明白你剩下的问题:)
我并不认为这是最好的方法,因为我的思想还没有完全围绕Python。在计算相图时,我已经编写了一个类似问题的解决方案。在给定的温度下,对于不同相数的自由能函数,总的最小自由能曲线是什么,在每个点上哪个函数是最小的。你知道吗
所以,最终的输出是一个总体最小值minG,以及它来自哪个曲线的指数minF。现在,如果您想细化交点,可以使用
返回线交叉的位置以及涉及哪些函数的索引。如果不同的函数真的是直线y=mx*b,你可以做代数运算得到精确的交叉。对于更复杂的函数,需要一个更复杂的过程(我将临时函数定义为所考虑的两个函数之间的差异,然后使用科学优化牛顿得到零)。你知道吗
相关问题 更多 >
编程相关推荐