sunode
sunode copied to clipboard
Non-constant parameters
Hi and thanks for this package!
I want to solve a set of ODEs where one of the parameters is a step function with prescribed times at which it can jump. What would be the recommended way of implementing something like that with sunode?
Any updates on this? Or on this page?
I solve this problem by python closure. The demo codes are as follows:
def get_dydt_func(prescribed_times_func):
def _dydt_func(c, y, params):
# use function variable prescribed_times_func in this block
pass
return _dydt_func
def prescribed_times_func1():
pass
def prescribed_times_func2():
pass
func1 = get_dydt_func(prescribed_times_func1)
func2 = get_dydt_func(prescribed_times_func2)
y_hat, _, problem, solver, _, _ =
sunode.wrappers.as_pytensor.solve_ivp(
y0=c0,
params=parames,
rhs=func1,
tvals=times,
t0=times[0],
)
Now, func1 has local and bind variable prescribed_times_func1 which value is 5, while it is prescribed_times_func2 in func2.