sunode icon indicating copy to clipboard operation
sunode copied to clipboard

Non-constant parameters

Open LSchueler opened this issue 4 years ago • 2 comments

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?

LSchueler avatar Aug 04 '21 12:08 LSchueler

Any updates on this? Or on this page?

LSchueler avatar Feb 15 '22 13:02 LSchueler

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.

makaspacex avatar Dec 21 '22 10:12 makaspacex