New answers tagged modeling
0
You do not need WhenEvent here as stated. You can use it though but you have to treat k as a function of t, that is a discrete state variable k[t].
Manipulate[
DynamicModule[{
sol = NDSolveValue[{
y'[t] == k[t] y[t],
y[0] == 10, k[0] == k0,
WhenEvent[t > 10, k[t] -> k[t] + s],
WhenEvent[t < 20, k[t] -> k[t] - s]
...
2
I'd like to extend the solution offered by Michael E2:
psol = ParametricNDSolve[{A'[t] == k1*A[t], A[0] == 10,
WhenEvent[t < 10, k1 -> (k1 + s)],
WhenEvent[t < 20, k1 -> (k1 - s)]},
A, {t, 0, 100}, {k1 \[Element] Reals, s \[Element] Reals}];
(*Plot[Evaluate[A[0.1, 0.2][t] /. psol], {t, 0, 30}]*)
Note that even in the case the DE ...
2
You don't need WhenEvent[] for this:
Manipulate[Plot[(A/. NDSolve[{A'[t] == (k1 + s HeavisidePi[1/10 (t - 15)]) A[t], A[0] == 10},
A, {t, 0, 100}] [[1]] )[x], {x, 0, 30}],
{k1, 0.0, 1.0}, {s, 0.0, 1.0}]
1
I don't think you can use WhenEvent to do what you want. The value of k1 is passed in the DE in NDSolve, not the symbol. WhenEvent has the attribute HoldAll, so that it deals with k1 and s as Symbols. Perhaps you could use ParametricNDSolve (see below).
Perhaps you want something like this?
kparam[t_?NumericQ, k1_, s_] := If[10 < t < 20, k1 + s, ...
Top 50 recent answers are included