float() argument must be a string or a number, not 'function' – solve_ivp

Question:

I have the following code:

def fun(t, s, rho_0, rho_1):
return lambda t, s:np.dot(np.array([0.775416, 0,0, 0.308968]).reshape(2,2), s) + np.array([rho_0,rho_1]).reshape(2,1)

def fun2(t, rho_0, rho_1):
    t_eval = np.arange(0,5)
    res = solve_ivp(fun, [0, 5], y0 = [0, 0], t_eval=t_eval, args = (rho_0, rho_1), vectorized = True)
    return res.y[1]

fun2(t = 0, rho_0 = 0.0099532, rho_1 = 0.001699)

which is giving the titled error. I am not exactly following why and how it can alternatively be expressed.

Asked By: Carl

||

Answers:

you returned a lambda expression in the function. In Python, lambda is an anonymous function. You don’t need to use lambda

def fun(t, s, rho_0, rho_1):
    return np.dot(np.array([0.775416, 0,0, 0.308968]).reshape(2,2), s) + np.array([rho_0,rho_1]).reshape(2,1)
Answered By: RedApple
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.