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.
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!
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
u<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 = u du = -p end # Model for the second region u<0 function f2(du,u,p,t) du = -2*u du = 0.5*p end function condition(u,t,integrator) # Switch model if u<0.0 u<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,