title: python syntax for functions with multiple return values: using fsolve
body: <p>I am new to python and trying to convert some matlab code as an exercise. One of the tasks involves finding the root, or minimum absolute value if no root exists, of a function. I can do that just fine, but I want to add some error checking to see that scipy.optimize.fsolve actually finds a solution. In particular, fsolve returns a parameter ier which is just a success flag and I want to read it. </p>
  
  <p>My code is as follows:</p>
  
  <pre><code>import numpy as np
  from scipy.optimize import fsolve, minimize
  
  mu = -8
  sigma = 4
  mun = -2
  ARL0 = 2000
  hmin = 0.5
  hmax = 100
  
  f = lambda h: (np.exp(-2*mun*(h/sigma+1.166))-1+2*mun*(h/sigma+1.166))/(2*mun**2)-ARL0
  
  if f(hmin)*f(hmax) &lt; 0:
      opth, ier = fsolve(f,hmax)
      print ier
      print opth[0]
  else:
      f = lambda h: np.abs((np.exp(-2*mun*(h/sigma+1.166))-1+2*mun*(h/sigma+1.166))/(2*mun**2)-ARL0)
      opth = minimize(f,hmax,bounds=((hmin,hmax),))
      print opth.success
      print opth.x[0]
  </code></pre>
  
  <p>The "else" bit works fine, it prints the solution and a true/false if it found one. The first if block doesn't: I get the following error when it runs: </p>
  
  <pre><code>line 14, in &lt;module&gt;
  opth, ier = fsolve(f,hmax)
  ValueError: need more than 1 value to unpack
  </code></pre>
  
  <p>I'm guessing it's just a synatx error but I haven't been able to find an example using fsolve to do this. Can someone point me in the right direction?</p>