@@ -69,7 +69,7 @@ function UnitMassWithFriction(k; name)
6969 @variables t x(t)=0 v(t)=0
7070 D = Differential(t)
7171 eqs = [D(x) ~ v
72- D(v) ~ sin(t) - k * sign(v)]
72+ D(v) ~ sin(t) - k * sign(v)]
7373 ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
7474end
7575@named m = UnitMassWithFriction(0.7)
@@ -94,7 +94,7 @@ root_eqs = [x ~ 0] # the event happens at the ground x(t) = 0
9494affect = [v ~ -v] # the effect is that the velocity changes sign
9595
9696@named ball = ODESystem([D(x) ~ v
97- D(v) ~ -9.8], t; continuous_events = root_eqs => affect) # equation => affect
97+ D(v) ~ -9.8], t; continuous_events = root_eqs => affect) # equation => affect
9898
9999ball = structural_simplify(ball)
100100
@@ -114,14 +114,14 @@ Multiple events? No problem! This example models a bouncing ball in 2D that is e
114114D = Differential(t)
115115
116116continuous_events = [[x ~ 0] => [vx ~ -vx]
117- [y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
117+ [y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
118118
119119@named ball = ODESystem([
120- D(x) ~ vx,
121- D(y) ~ vy,
122- D(vx) ~ -9.8 - 0.1vx, # gravity + some small air resistance
123- D(vy) ~ -0.1vy,
124- ], t; continuous_events)
120+ D(x) ~ vx,
121+ D(y) ~ vy,
122+ D(vx) ~ -9.8 - 0.1vx, # gravity + some small air resistance
123+ D(vy) ~ -0.1vy,
124+ ], t; continuous_events)
125125
126126ball = structural_simplify(ball)
127127
@@ -189,7 +189,7 @@ affect interface:
189189sts = @variables x(t), v(t)
190190par = @parameters g = 9.8
191191bb_eqs = [D(x) ~ v
192- D(v) ~ -g]
192+ D(v) ~ -g]
193193
194194function bb_affect!(integ, u, p, ctx)
195195 integ.u[u.v] = -integ.u[u.v]
198198reflect = [x ~ 0] => (bb_affect!, [v], [], nothing)
199199
200200@named bb_model = ODESystem(bb_eqs, t, sts, par,
201- continuous_events = reflect)
201+ continuous_events = reflect)
202202
203203bb_sys = structural_simplify(bb_model)
204204u0 = [v => 0.0, x => 1.0]
@@ -288,7 +288,7 @@ killing = (t == tkill) => [α ~ 0.0]
288288tspan = (0.0, 30.0)
289289p = [α => 100.0, tinject => 10.0, M => 50, tkill => 20.0]
290290@named osys = ODESystem(eqs, t, [N], [α, M, tinject, tkill];
291- discrete_events = [injection, killing])
291+ discrete_events = [injection, killing])
292292oprob = ODEProblem(osys, u0, tspan, p)
293293sol = solve(oprob, Tsit5(); tstops = [10.0, 20.0])
294294plot(sol)
@@ -316,7 +316,7 @@ killing = [20.0] => [α ~ 0.0]
316316
317317p = [α => 100.0, M => 50]
318318@named osys = ODESystem(eqs, t, [N], [α, M];
319- discrete_events = [injection, killing])
319+ discrete_events = [injection, killing])
320320oprob = ODEProblem(osys, u0, tspan, p)
321321sol = solve(oprob, Tsit5())
322322plot(sol)
0 commit comments