0

My whole program is right (I've checked at various stages). The highlighted line in this module, however, returns the error:

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

I don't know why this is happening. funcPsat returns float value. I would appreciate any useful advice!

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
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Pearl Philip
  • 883
  • 2
  • 11
  • 16

1 Answers1

4

I think the problem is that, per the documentation

args: tuple, optional

Extra arguments to be used in the function call.

the args argument should be a tuple.

Just putting parentheses won't do it; the syntax for tuples is the comma. For example:

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

Try:

solution = newton(self.funcPsat, Pguess, args=(T,))
                                              # ^ note comma
Community
  • 1
  • 1
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437