0

我的整个程序是正确的(我已经在各个阶段进行了检查)。但是,此模块中突出显示的行返回错误:

TypeError: can only concatenate tuple (not "int") to tuple

我不知道为什么会这样。funcPsat返回浮点值。我将不胜感激任何有用的建议!

import scipy.optimize.newton as newton

def Psat(self, T):
    pop= self.getPborder(T)
    boolean=int(pop[0])
    P1=pop[1]
    P2=pop[2]
    if boolean:
        Pmin = min([P1, P2])
        Pmax = max([P1, P2])
        if Pmin > 0.0: 
            Pguess = 0.5*(Pmin+Pmax) 
        else:
            Pguess=0.5*Pmax
        solution = newton(self.funcPsat, Pguess, args=(T))   #error in this line
        return solution
    else:
        return None
4

1 回答 1

4

我认为问题在于,根据文档

args 元组,可选

要在函数调用中使用的额外参数。

args参数应该是a tuple

只加括号是不行的;元组的语法是逗号。例如:

>>> T = 0
>>> type((T))
<type 'int'>
>>> type((T,))
<type 'tuple'>

尝试:

solution = newton(self.funcPsat, Pguess, args=(T,))
                                              # ^ note comma
于 2014-06-10T11:21:06.313 回答