Created
February 6, 2017 15:53
-
-
Save ChrisRackauckas/49ab10bfbf872c4cfedc06f25aef06aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
using ParameterizedFunctions | |
params = [0.0] | |
function dyn_eq(t,u,params,du) | |
du .= [0 1; | |
0 0]*u + [0;1]*params[1] | |
end | |
p_dyn_eq = ParameterizedFunction(dyn_eq,params) | |
tf = 30.0 | |
tstops = collect(0:1:tf) | |
function condition_control_loop(t,u,integrator) | |
(t in tstops) | |
end | |
r = 10.0 | |
k = 0.3 | |
d = 0.8 | |
function control_loop!(integrator) | |
params = integrator.f.params | |
p = integrator.u[1] | |
v = integrator.u[2] | |
params[1] = k*(r-p) + d*(0.0-v) | |
end | |
cb = DiscreteCallback(condition_control_loop, control_loop!) | |
u0 = [0.0; 0.0] | |
prob = ODEProblem(p_dyn_eq, u0, (0.0, tf)) | |
sol = solve(prob, Tsit5(), callback = cb, tstops=tstops) | |
using Plots; pyplot() | |
plot(sol) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment