-
-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathparameters.jl
More file actions
38 lines (32 loc) · 1.14 KB
/
parameters.jl
File metadata and controls
38 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using DelayDiffEq
using OrdinaryDiffEqTsit5
using Test
# Test parameterized delayed logistic equation
# delayed logistic equation
f_inplace(du, u, h, p, t) = (du[1] = p[1] * u[1] * (1 - h(p, t - 1; idxs = 1)))
f_scalar(u, h, p, t) = p[1] * u * (1 - h(p, t - 1))
# simple history function
h(p, t; idxs = nothing) = 0.1
@testset for inplace in (true, false)
# define problem
# we specify order_discontinuity_t0 = 1 to indicate that the discontinuity at
# t = 0 is of first order
prob = DDEProblem(
inplace ? f_inplace : f_scalar,
inplace ? [0.1] : 0.1,
h, (0.0, 50.0), [0.3];
constant_lags = [1],
order_discontinuity_t0 = 1
)
# solve problem with initial parameter:
sol1 = solve(prob, MethodOfSteps(Tsit5()))
@test 15 <= length(sol1) <= 25
@test first(sol1(12)) ≈ 0.884 atol = 1.0e-3
@test first(sol1.u[end]) ≈ 1 atol = 1.0e-4
# solve problem with updated parameter
prob.p[1] = 1.4
sol2 = solve(prob, MethodOfSteps(Tsit5()))
@test 40 <= length(sol2) <= 60
@test first(sol2(12)) ≈ 1.125 atol = 5.0e-3
@test first(sol2.u[end]) ≈ 0.994 atol = 2.0e-3
end