bucky.util.ode_constraints

Constrant decorators for the RHS funcs used in the ODE solvers

Module Contents

Functions

constrain_y_range(constraints)

Decorator which wraps a function to be passed to an ODE solver which constrains the solution space.

bucky.util.ode_constraints.constrain_y_range(constraints)[source]

Decorator which wraps a function to be passed to an ODE solver which constrains the solution space.

Note that this constrains the dependent variable from going any further past the constraints. The ODE will still treat it as if it were at the value of the constraint, and with a small step size any problems should be minimal, but you may still have slightly out-of-range numbers in your solution.

Example:

@constrain([0, 1]) def f(t, y)

dy_dt = # your ODE return dy/dt

solver = scipy.integrate.odeint(f, y0) # use any solver you like! solution = solver.solve()

If solution goes below 0 or above 1, the function f will ignore values of dy_dt which would make it more extreme, and treat the previous solution as if it were at 0 or 1.

Params constraints

Sequence of (low, high) constraints - use None for unconstrained.