Skip to content

Instantly share code, notes, and snippets.

@ronisbr
Created January 29, 2017 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronisbr/c4b3169dfd44d231a9f5f1866538e242 to your computer and use it in GitHub Desktop.
Save ronisbr/c4b3169dfd44d231a9f5f1866538e242 to your computer and use it in GitHub Desktop.
using DiffEqBase
using OrdinaryDiffEq
function f(t,u)
du = similar(u)
du[1] = u[2]
du[2] = -9.81
du
end
function condition(t,u,integrator) # Event when event_f(t,u) == 0
u[1]
end
function apply_event!(integrator)
integrator.u[2] = -integrator.u[2]
end
rootfind = true
save_positions = (true,true)
cb = ContinuousCallback(condition,apply_event!,rootfind,save_positions)
u0 = [50.0,0.0]
tspan = (0.0,15.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob,Tsit5(),callback=cb,saveat=collect(0:0.1:15),dtmin=2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment