Created
January 29, 2017 16:46
-
-
Save ronisbr/c4b3169dfd44d231a9f5f1866538e242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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