|
| 1 | +# DDE examples with analytical solution |
| 2 | + |
| 3 | +## Single constant delay |
| 4 | + |
| 5 | +### In-place function |
| 6 | + |
| 7 | +f_1delay = function (t,u,h,du) |
| 8 | + du[1] = - h(t-1)[1] |
| 9 | +end |
| 10 | + |
| 11 | +function (f::typeof(f_1delay))(::Type{Val{:analytic}}, t, u₀) |
| 12 | + if t < 0 |
| 13 | + return 0 |
| 14 | + elseif t < 1 |
| 15 | + return u₀ |
| 16 | + elseif t < 2 |
| 17 | + return u₀ * (2 - t) |
| 18 | + elseif t < 3 |
| 19 | + return u₀ * (8 - 6t + t^2) / 2 |
| 20 | + elseif t < 4 |
| 21 | + return u₀ * (51 - 45t + 12t^2 - t^3) / 6 |
| 22 | + elseif t < 5 |
| 23 | + return u₀ * (460 - 436t + 144t^2 - 20t^3 + t^4) / 24 |
| 24 | + elseif t < 6 |
| 25 | + return u₀ * (5_425 - 5_305t + 1_970t^2 - 350t^3 + 30t^4 - t^5) / 120 |
| 26 | + elseif t < 7 |
| 27 | + return u₀ * (79_206 - 78_486t + 31_260t^2 - 6_420t^3 + 720t^4 - 42t^5 + t^6) / 720 |
| 28 | + elseif t < 8 |
| 29 | + return u₀ * (1_377_985 - 1_372_945t + 571_767t^2 - 128_975t^3 + 17_045t^4 - |
| 30 | + 1_323t^5 + 56t^6 - t^7) / 5040 |
| 31 | + elseif t < 9 |
| 32 | + return u₀ * (27_801_096 - 27_760_776t + 11_914_168t^2 - 2_866_808t^3 + 423_080t^4 - |
| 33 | + 39_256t^5 + 2_240t^6 - 72t^7 + t^8) / 40_320 |
| 34 | + elseif t ≤ 10 |
| 35 | + return u₀ * (637_630_353 - 637_267_473t + 279_414_396t^2 - 70_442_316t^3 + |
| 36 | + 11_247_894t^4 - 1_179_990t^5 + 81_396t^6 - 3_564t^7 + 90t^8 - t^9) / |
| 37 | + 362_880 |
| 38 | + else |
| 39 | + error("This analytical solution is only valid on (-∞,10]") |
| 40 | + end |
| 41 | +end |
| 42 | + |
| 43 | +""" |
| 44 | + prob_dde_1delay(u₀) |
| 45 | +
|
| 46 | +Model problem of finding a solution ``u(t)`` in the time span ``t \\in [0,10]`` to the |
| 47 | +delay differential equation |
| 48 | +
|
| 49 | +```math |
| 50 | +\\frac{du}{dt} = -u(t-1) |
| 51 | +``` |
| 52 | +
|
| 53 | +with history function |
| 54 | +
|
| 55 | +```math |
| 56 | +u(t) = \\begin{cases} |
| 57 | +0 & \\text{if } t < 0, \\ |
| 58 | +u₀ & \\text{if } t = 0, |
| 59 | +\\end{cases} |
| 60 | +``` |
| 61 | +
|
| 62 | +for ``t \\leq 0``. Hence the problem is discontinuous at ``t = 0`` for all ``u₀ \\neq 0``. |
| 63 | +
|
| 64 | +An analytical solution of this problem is provided for ``t \\in (-\\infty,10]``. |
| 65 | +""" |
| 66 | +prob_dde_1delay(u₀) = ConstantLagDDEProblem(f_1delay, t->[0.0], [u₀], [1], (0.0, 10.0); |
| 67 | + iip=true) |
| 68 | + |
| 69 | +### Not in-place function |
| 70 | + |
| 71 | +f_1delay_notinplace = function (t,u,h) |
| 72 | + - h(t-1) |
| 73 | +end |
| 74 | + |
| 75 | +(f::typeof(f_1delay_notinplace))(::Type{Val{:analytic}}, t, u0) = f_1delay(Val{:analytic}, |
| 76 | + t, u0) |
| 77 | + |
| 78 | +#### Vectorized history function |
| 79 | + |
| 80 | +""" |
| 81 | + prob_dde_1delay_notinplace(u₀) |
| 82 | +
|
| 83 | +Same as [`prob_dde_1delay`](@ref), but purposefully implemented with a not in-place |
| 84 | +function. |
| 85 | +""" |
| 86 | +prob_dde_1delay_notinplace(u₀) = |
| 87 | + ConstantLagDDEProblem(f_1delay_notinplace, t->[0.0], [u₀], [1], (0.0, 10.0); iip=false) |
| 88 | + |
| 89 | +#### Scalar history function |
| 90 | + |
| 91 | +""" |
| 92 | + prob_dde_1delay_scalar_notinplace(u₀) |
| 93 | +
|
| 94 | +Same as [`prob_dde_1delay_notinplace`](@ref), but purposefully implemented with a scalar |
| 95 | +history function. |
| 96 | +""" |
| 97 | +prob_dde_1delay_scalar_notinplace(u₀) = |
| 98 | + ConstantLagDDEProblem(f_1delay_notinplace, t->0.0, u₀, [1], (0.0, 10.0); iip=false) |
| 99 | + |
| 100 | +## Two constant delays |
| 101 | + |
| 102 | +### In-place function |
| 103 | + |
| 104 | +f_2delays = function (t,u,h,du) |
| 105 | + du[1] = - h(t-1/3)[1] - h(t-1/5)[1] |
| 106 | +end |
| 107 | + |
| 108 | +function (f::typeof(f_2delays))(::Type{Val{:analytic}}, t, u₀) |
| 109 | + if t < 0 |
| 110 | + return 0 |
| 111 | + elseif t < 1/5 |
| 112 | + return u₀ |
| 113 | + elseif t < 1/3 |
| 114 | + return u₀ * (6 - 5t) / 5 |
| 115 | + elseif t < 2/5 |
| 116 | + return u₀ * (23 - 30t) / 15 |
| 117 | + elseif t < 8/15 |
| 118 | + return u₀ * (242 - 360t + 75t^2) / 150 |
| 119 | + elseif t < 3/5 |
| 120 | + return u₀ * (854 - 1_560t + 675t^2) / 450 |
| 121 | + elseif t < 2/3 |
| 122 | + return u₀ * (4_351 - 8_205t + 4_050t^2 - 375t^3) / 2_250 |
| 123 | + elseif t < 11/15 |
| 124 | + return u₀ * (1_617 - 3_235t + 1_725t^2 - 125t^3) / 750 |
| 125 | + elseif t < 4/5 |
| 126 | + return u₀ * (7_942 - 17_280t + 11_475t^2 - 2_250t^3) / 3_375 |
| 127 | + elseif t < 13/15 |
| 128 | + return u₀ * (319_984 - 702_720t + 480_600t^2 - 108_000t^3 + 5_625t^4) / 135_000 |
| 129 | + elseif t < 14/15 |
| 130 | + return u₀ * (40_436 - 94_980t + 72_900t^2 - 19_500t^3 + 625t^4) / 15_000 |
| 131 | + elseif t ≤ 1 |
| 132 | + return u₀ * (685_796 - 1_670_388t + 1_392_660t^2 - 467_100t^3 + 50_625t^4) / 243_000 |
| 133 | + else |
| 134 | + error("This analytical solution is only valid on (-∞,1]") |
| 135 | + end |
| 136 | +end |
| 137 | + |
| 138 | +""" |
| 139 | + prob_dde_2delays(u₀) |
| 140 | +
|
| 141 | +Model problem of finding a solution ``u(t)`` in the time span ``t \\in [0,1]`` to the delay |
| 142 | +differential equation |
| 143 | +
|
| 144 | +```math |
| 145 | +\\frac{du}{dt} = -u(t-1/3)-u(t-1/5) |
| 146 | +``` |
| 147 | +
|
| 148 | +with history function |
| 149 | +
|
| 150 | +```math |
| 151 | +u(t) = \\begin{cases} |
| 152 | +0 & \text{if } t < 0 \\ |
| 153 | +u₀ & \text{if } t = 0 |
| 154 | +\end{cases} |
| 155 | +``` |
| 156 | +
|
| 157 | +for ``t \\leq 0``. Hence the problem is discontinuous at ``t = 0`` for all ``u₀ \\neq 0``. |
| 158 | +
|
| 159 | +An analytical solution of this problem is provided for ``t \\in (-\\infty,1]``. |
| 160 | +""" |
| 161 | +prob_dde_2delays(u₀) = ConstantLagDDEProblem(f_2delays, t->[0.0], [u₀], [1//3, 1//5], |
| 162 | + (0.0, 1.0); iip=true) |
| 163 | + |
| 164 | +### Not in-place function |
| 165 | + |
| 166 | +f_2delays_notinplace = function (t,u,h) |
| 167 | + - h(t-1/3) - h(t-1/5) |
| 168 | +end |
| 169 | + |
| 170 | +(f::typeof(f_2delays_notinplace))(::Type{Val{:analytic}}, t, u0) = |
| 171 | + f_2delays(Val{:analytic}, t, u0) |
| 172 | + |
| 173 | +#### Vectorized history function |
| 174 | + |
| 175 | +""" |
| 176 | + prob_dde_2delays_notinplace(u₀) |
| 177 | +
|
| 178 | +Same as [`prob_dde_2delays`](@ref), but purposefully implemented with a not in-place |
| 179 | +function. |
| 180 | +""" |
| 181 | +prob_dde_2delays_notinplace(u₀) = |
| 182 | + ConstantLagDDEProblem(f_2delays_notinplace, t->[0.0], [u₀], [1//3, 1//5], (0.0, 1.0); |
| 183 | + iip=false) |
| 184 | + |
| 185 | +#### Scalar history function |
| 186 | + |
| 187 | +""" |
| 188 | + prob_dde_2delays_scalar_notinplace(u₀) |
| 189 | +
|
| 190 | +Same as [`prob_dde_2delays_notinplace`](@ref), but purposefully implemented with a scalar |
| 191 | +history function. |
| 192 | +""" |
| 193 | +prob_dde_2delays_scalar_notinplace(u₀) = |
| 194 | + ConstantLagDDEProblem(f_2delays_notinplace, t->0.0, u₀, [1//3, 1//5], (0.0, 1.0); |
| 195 | + iip=false) |
| 196 | + |
| 197 | +# DDE examples without analytical solution |
| 198 | + |
| 199 | +## Single constant delay |
| 200 | + |
| 201 | +### In-place function |
| 202 | + |
| 203 | +f_1delay_long = function (t,u,h,du) |
| 204 | + du[1] = - h(t-0.2)[1] + u[1] |
| 205 | +end |
| 206 | + |
| 207 | +""" |
| 208 | +Model problem of finding a solution ``u(t)`` in the time span ``t \\in [0,100]`` to the |
| 209 | +delay differential equation |
| 210 | +
|
| 211 | +```math |
| 212 | +\\frac{du}{dt} = -u(t-0.2) + u(t) |
| 213 | +``` |
| 214 | +
|
| 215 | +with history function |
| 216 | +
|
| 217 | +```math |
| 218 | +u(t) = \\begin{cases} |
| 219 | +0 & \\text{if } t < 0,\\ |
| 220 | +1 & \\text{if } t = 0, |
| 221 | +\\end{cases} |
| 222 | +``` |
| 223 | +
|
| 224 | +for ``t \\leq 0``. Hence the problem is discontinuous at ``t = 0``. |
| 225 | +""" |
| 226 | +prob_dde_1delay_long = ConstantLagDDEProblem(f_1delay_long, t->[0.0], [1.0], [0.2], |
| 227 | + (0.0, 100.0); iip=true) |
| 228 | + |
| 229 | +### Not in-place function |
| 230 | + |
| 231 | +f_1delay_long_notinplace = function (t,u,h) |
| 232 | + - h(t-0.2) + u |
| 233 | +end |
| 234 | + |
| 235 | +""" |
| 236 | +Same as [`prob_dde_1delay_long`](@ref), but purposefully implemented with a not in-place |
| 237 | +function. |
| 238 | +""" |
| 239 | +prob_dde_1delay_long_notinplace = |
| 240 | + ConstantLagDDEProblem(f_1delay_long_notinplace, t->[0.0], [1.0], [0.2], (0.0, 100.0); |
| 241 | + iip=false) |
| 242 | + |
| 243 | +""" |
| 244 | +Same as [`prob_dde_1delay_long_notinplace`](@ref), but purposefully implemented with a |
| 245 | +scalar history function. |
| 246 | +""" |
| 247 | +prob_dde_1delay_long_scalar_notinplace = |
| 248 | + ConstantLagDDEProblem(f_1delay_long_notinplace, t->0.0, 1.0, [0.2], (0.0, 100.0); |
| 249 | + iip=false) |
| 250 | + |
| 251 | +## Two constant delays |
| 252 | + |
| 253 | +### In-place function |
| 254 | + |
| 255 | +f_2delays_long = function (t,u,h,du) |
| 256 | + du[1] = - h(t-1/3)[1] - h(t-1/5)[1] |
| 257 | +end |
| 258 | + |
| 259 | +""" |
| 260 | +Model problem of finding a solution ``u(t)`` in the time span ``t \\in [0,100]`` to the |
| 261 | +delay differential equation |
| 262 | +
|
| 263 | +```math |
| 264 | +\\frac{du}{dt} = -u(t-1/3) - u(1-1/5) |
| 265 | +``` |
| 266 | +
|
| 267 | +with history function |
| 268 | +
|
| 269 | +```math |
| 270 | +u(t) = \\begin{cases} |
| 271 | +0 & \\text{if } t < 0,\\ |
| 272 | +1 & \\text{if } t = 0, |
| 273 | +\\end{cases} |
| 274 | +``` |
| 275 | +
|
| 276 | +for ``t < 0``. Hence the problem is discontinuous at ``t = 0``. |
| 277 | +""" |
| 278 | +prob_dde_2delays_long = ConstantLagDDEProblem(f_2delays_long, t->[0.0], [1.0], [1//3, 1//5], |
| 279 | + (0.0, 100.0); iip=true) |
| 280 | + |
| 281 | +### Not in-place function |
| 282 | + |
| 283 | +f_2delays_long_notinplace = function (t,u,h) |
| 284 | + - h(t-1/3) - h(t-1/5) |
| 285 | +end |
| 286 | + |
| 287 | +#### Vectorized history function |
| 288 | + |
| 289 | +""" |
| 290 | +Same as [`prob_dde_2delays_long`](@ref), but purposefully implemented with a not in-place |
| 291 | +function. |
| 292 | +""" |
| 293 | +prob_dde_2delays_long_notinplace = |
| 294 | + ConstantLagDDEProblem(f_2delays_long_notinplace, t->[0.0], [1.0], [1//3, 1//5], |
| 295 | + (0.0, 100.0); iip=false) |
| 296 | + |
| 297 | +#### Scalar history function |
| 298 | + |
| 299 | +""" |
| 300 | +Same as [`prob_dde_2delays_long_notinplace`](@ref), but purposefully implemented with a scalar |
| 301 | +history function. |
| 302 | +""" |
| 303 | +prob_dde_2delays_long_scalar_notinplace = |
| 304 | + ConstantLagDDEProblem(f_2delays_long_notinplace, t->0.0, 1.0, [1//3, 1//5], |
| 305 | + (0.0, 100.0); iip=false) |
0 commit comments