title: Python Scipy - Solve same scalar equation for two different variables
body: <p>In my algorithm I need to solve the same equation twice for two different variables. At the moment I am using scipy.fsolve and I have defined two different functions respectively for the first and second iteration.</p>
  
  <p>The first time I solve for X and I pass a certain number of parameters, including Y.
  The second time I need to solve for Y while X becomes one of the parameters. Of course, in this second iteration some of the original parameters also need to be changed.</p>
  
  <p>This is the simplified code</p>
  
  <pre><code>def f1(X, *params1):
      (Y, a, b, c) = params1
      long procedure...
      return S
  def f2(Y, *params2):
      (X, a, b, c) = params2
      same long procedure....
      return S
  params1 = (Y, a1, b1, c1)
  X = fsolve(f1, X0, args=params1)
  params2 = (X, a1, b2, c2)
  Y = fsolve(f2, Y0, args=params2)
  </code></pre>
  
  <p>Is there a way to organize the code in a more elegant way, by reusing the same function?</p>