I am kind of looking for a mixed solution of the proposed answer of this thread. The first code snippet is using a more symbolic way, which I am after with the property of the second code snippet where the number of variables change. So something close to this where number of variables n can change.
from sympy import *
from scipy.optimize import minimize
from sympy.utilities.lambdify import lambdify
x, i, n = symbols("x i n")
n = 10
func = Sum((Indexed('x',i)-3)/(1+0.2)**i,(i,1,n))
my_func = lambdify((x, i, n), func)
def my_func_v(x):
return my_func(*tuple(x))
results = minimize(my_func_v, np.zeros(n))
Any ideas?