Hello everyone,

I would like to solve an ODE in DifferentialEquations.jl where the right-hand side and the time step depend on the region where is located the particle.

The function `DiscreteCallBack`

seems to be adequate for my problem.

But I don’t know how to change the right hand of the ODEProblem in the function affect!

From http://docs.juliadiffeq.org/latest/basics/integrator.html,

`integrator.f`

should be the function being solved

Here a simplified example of what I am trying to do:

We have a particle whose dynamic is governed by a first function `f1`

. When `u[1]<0.0`

, we want to switch to a second dynamic `f2`

and change the time step

```
using OrdinaryDiffEq
# Model for the first region u[1=]>0
function f1(du,u,p,t)
du[1] = u[2]
du[2] = -p
end
# Model for the second region u[2]<0
function f2(du,u,p,t)
du[1] = -2*u[2]
du[2] = 0.5*p
end
function condition(u,t,integrator) # Switch model if u[1]<0.0
u[1]<0.0
end
function affect!(integrator)
integrator.f = f2
set_proposed_dt!(integrator,0.01)
end
cb = DiscreteCallback(condition,affect!)
u0 = [50.0,0.0]
tspan = (0.0,15.0)
p = 9.8
prob = ODEProblem(f1,u0,tspan,p)
sol = solve(prob,RK4(), dt = 0.1, callback=cb)
```

Thank you for your help,