You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seem to be a couple of weird behaviors when using discrete_events in MTK9. For example, when setting a period of 24 hours for a periodic input into a state, the last event seems to double the input amount.
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
using Plots
functionMTK_func(;name)
pars =@parametersbegin
input =10.0end
D =Differential(t)
vars =@variablesbeginA(t) =0.0end
eqs = [D(A) ~-A]
ODESystem(eqs, t, vars, pars; discrete_events = [24.0=> [A ~ A + input]], name = name)
end@mtkbuild mtkmod =MTK_func()
tspan = (0.0, 130.0); # [hr], 28 days
prob =ODEProblem(mtkmod, Pair[], tspan);
sol =solve(prob);
Plots.plot(sol)
And if you use a vector of event times and happen to include 0.0, even though it should have no effect, it skips the first event...
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
using Plots
functionMTK_func(input_times;name)
pars =@parametersbegin
input =10.0end
D =Differential(t)
vars =@variablesbeginA(t) =0.0end
eqs = [D(A) ~-A]
ODESystem(eqs, t, vars, pars; discrete_events = [input_times => [A ~ A + input]], name = name)
end@mtkbuild mtk1 =PK_func([0.0, 24.0, 48.0, 96.0])
@mtkbuild mtk2 =PK_func([24.0, 48.0, 96.0])
tspan = (0.0, 130.0); # [hr], 28 days
prob1 =ODEProblem(mtk1, Pair[], tspan);
prob2 =ODEProblem(mtk2, Pair[], tspan);
sol1 =solve(prob1, saveat=0.1);
sol2 =solve(prob2, saveat=0.1);
Plots.plot(sol1)
Plots.plot!(sol2)
There seem to be a couple of weird behaviors when using discrete_events in MTK9. For example, when setting a period of 24 hours for a periodic input into a state, the last event seems to double the input amount.
And if you use a vector of event times and happen to include 0.0, even though it should have no effect, it skips the first event...
The text was updated successfully, but these errors were encountered: