python - Scipy.optimize.minimize giving error when passed a single parameter with args -


given following values

a = 100.0 b = 50.0 c = 200.0 

the following code works (it doesn't interesting)

def excessrevenue1(taxh,blah1,blah2):     return taxh**2 + blah1 + blah2     print optimize.minimize( excessrevenue1,c,args=(a,b) ).x 

but following code produces error << typeerror: can concatenate tuple (not "float") tuple >>. difference seems passing 1 argument instead of two.

def excessrevenue2(taxh,blah1):     return taxh**2 + blah1 print optimize.minimize( excessrevenue2,c,args=(a) ).x 

right python thinks args argument float, not tuple have add comma.

print optimize.minimize( excessrevenue2,c,args=(a,)).x 

so then, function work expected, i.e.:

from scipy import optimize  = 100.0 b = 50.0 c = 199.9  def excessrevenue1(taxh,blah1,blah2):     return taxh**2 + blah1 + blah2  def excessrevenue2(taxh,blah1):     return taxh**2 + blah1  print optimize.minimize( excessrevenue2,c,args=(a,)).x print optimize.minimize(excessrevenue1,c,args=(a,b)).x 

would return:

>>> print optimize.minimize( excessrevenue2,c,args=(a,)).x [ -1.65480420e-07] >>> print optimize.minimize(excessrevenue1,c,args=(a,b)).x [ -1.65480420e-07] 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -