title: indexing in lambda function to optimize multiple variables of a sum
body: <p>I want to solve an optimization problem as proposed in <a href="https://stackoverflow.com/questions/47187841/python-optimization-indexed-sum-using-sympy-lambdify-and-scipy/47208090#47208090">this</a> thread. Now, I not only want to solve for the <code>x[1]...x[n]</code>, but also for the variable y. It looks like something is wrong with the indexing.</p>
  
  <pre><code>from sympy import Sum, symbols, Indexed, lambdify
  from scipy.optimize import minimize
  import numpy as np
  
  def _eqn(y, variables, periods, sign=-1.0):
      x, i = symbols("x i")
      n = periods-1
      s = Sum(Indexed('x', i)/(1+0.06)**i, (i, 1, n))
      f = lambdify(x, s, modules=['sympy'])
      return float(sign*(y + f(variables)))
  
  z = 3
  results = minimize(lambda xy: _eqn(xy[0], xy[1:z], z),np.zeros(z))
  print(results.x)
  </code></pre>