RecipePythonIntermediate
Derive a Jacobian with SymPy and pass it to solve_ivp with lambdify
- f = sp.lambdify((t, y), list(rhs.subs(rates)), "numpy") # list: a flat vector, as solve_ivp wants
- jac = sp.lambdify((t, y), J.subs(rates), "numpy") # (t, y) even though t does not appear
- f_column = sp.lambdify((t, y), rhs.subs(rates), "numpy")
- times_euler = sp.lambdify(e, e * sp.E, "numpy")
- print(sp.lambdify(electron, electron * sp.E, "numpy")(2.0))
- jac_y = sp.lambdify(y, J.subs(rates), "numpy")
and 1 more line in this tutorial