Skip to content Skip to sidebar Skip to footer

Python Optimization Indexed Sum Using Sympy Lambdify And Scipy

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 seco

Solution 1:

So this seems to do the trick:

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, 0, n))
    f = lambdify(x, s, modules=['sympy'])
    returnfloat(sign*(y + f(variables)))

z = 3
results = minimize(lambda x: _eqn(3, x, z),np.zeros(z))
print(results.x)

Any further suggestions?

Post a Comment for "Python Optimization Indexed Sum Using Sympy Lambdify And Scipy"