1

我正在尝试通过 scipy.optimize.curve_fit 找到函数的最佳拟合参数这是代码

def y_position(b, E, time):

    a = 0.75/100
    b = 40
    T = 40
    dty = 7*60
    e=pickle.load(open("aclass.die", "rb"))
    array = []
    return_y = 0
    for f in e.frag:
        t = 0
        while t < time:
              f.position_in_y(f.num, a, E, dty, b, T)
              t += dty
        array.append(f.ypos)
#rescale
    minus = max(array)
    for j in range(len(array)):
        array[j] = array[j]-minus
    divid = min(array)
    for i in range(len(array)):
        array[i] = array[i]/divid

    for n in range(len(e.frag)):
        if e.frag[n].num == b:
           return_y = array[n]
    return return_y


exper_y=[0, 1.0, 0.780, 0.640, 0.240, 0.680]
x =[638, 78, 643, 71, 534, 303]

po = [28, 500]
po, cov = optimize.curve_fit(y_position, x, exper_y, p0=po)

print po  
exit()

我已经在其他文件中定义了所需的类,并在开始时肯定会导入它。这position_in_y是 frag 类中的一个函数,我的函数有点复杂,但我想仍然合乎逻辑。我得到了错误:

TypeError: unsupported operand type(s) for -: 'int' and 'list'

在我运行它之后。我不明白为什么会这样。请帮忙!!!提前致谢

4

0 回答 0