Skip to content

Non-constant parameters #24

Open
Open

Description

@LSchueler

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?

Activity

  1. LSchueler commented on Feb 15, 2022

    @LSchueler
    Author

    Any updates on this? Or on this page?

  2. makaspacex commented on Dec 21, 2022

    @makaspacex

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions