title: Solving nonlinear simultaneous equations using `minimize` in Python
body: <p>I want to solve two simultaneous equations using the <a href="https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.minimize.html" rel="nofollow noreferrer"><code>scipy.optimize.minimize</code></a> function in Python, specifically with the <a href="https://docs.scipy.org/doc/scipy-0.18.1/reference/optimize.minimize-dogleg.html#optimize-minimize-dogleg" rel="nofollow noreferrer">dog-leg trust-region</a> algorithm. This requires me to specify the Jacobian of the problem by using <a href="http://scipy.github.io/devdocs/generated/scipy.optimize.approx_fprime.html" rel="nofollow noreferrer"><code>scipy.optimize.approx_fprime</code></a>, as suggested in <a href="https://stackoverflow.com/questions/40975133/optimization-algorithm-dog-leg-trust-region-in-matlab-and-python/40981143#40981143">one solution to my other post</a>.</p>
  
  <p>My MWE is:</p>
  
  <pre><code>import numpy as np
  from scipy.integrate import quad
  from scipy.optimize import minimize,approx_fprime
  
  def myfunc(guess,a,b,c,d):
  
      # initial guesses
      x0 = guess[0]
      x1 = guess[1]
  
      # functions
      z0 = lambda x: c*np.sqrt(a**3*x0)*np.sin(x)/x0**b
      z1 = lambda x: np.cos(b*x0*x)/x1**a
  
      # numerical integration with 'quad'
      z0int = quad(z0,-200,200,epsabs=1e-8,epsrel=1e-6)[0] - 3.2*d
      z1int = quad(z1,-200,200,epsabs=1e-8,epsrel=1e-6)[0] + c
  
      return (z0int,z1int)
  
  # constants
  a = 0.2
  b = 1.1
  c = 2.5
  d = 0.9
  
  guess = np.array([0.3,0.02]) # initial guesses
  
  myJac = approx_fprime(guess,myfunc,1e-9,a,b,c,d) # Jacobian
  
  # minimisation, want to find x0 such that z0int=0 and z1int=0
  xopt = minimize(myfunc,guess,args=(a,b,c,d),method='dogleg',jac=myJac)
  
  print(xopt)
  </code></pre>
  
  <p>However I get an error <code>TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'</code>. I'm not really familiar with the Python optimization functions so could you please explain what is wrong and how to correct the code?</p>