-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65e829b
commit 47434b8
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using OrdinaryDiffEq | ||
using DiffEqCallbacks | ||
using Plots | ||
|
||
function f(u, p, t) | ||
a, d, e = p | ||
return u * (a - d) + e | ||
end | ||
|
||
u0 = 1.0 | ||
p = [0.0, 1.0, 1.0] | ||
tspan = (0.0, 100.0) | ||
prob = ODEProblem(f, u0, tspan, p) | ||
|
||
function make_events(start_time, end_time, pulse_width, period, strength=2.0) | ||
function go_up!(integrator) | ||
integrator.p[1] = strength | ||
integrator.p[3] = 0.0 | ||
end | ||
|
||
function go_down!(integrator) | ||
integrator.p[1] = 0.0 | ||
integrator.p[3] = 1.0 | ||
end | ||
|
||
upevents = PresetTimeCallback(start_time:period:end_time, go_up!) | ||
downevents = PresetTimeCallback(start_time+pulse_width:period:end_time, go_down!) | ||
return CallbackSet(upevents, downevents) | ||
end | ||
|
||
alg = Tsit5() | ||
events = make_events(tspan[begin], tspan[end], 1.0, 10.0) | ||
|
||
sol = solve(prob, alg, callback=events) | ||
|
||
plot(sol) |