Using WhenEvent
inside Module
is quite strange. The local variables are not evaluated in WhenEvent
. For example
eq = Module[{time1 = 200, time2 = 400},
{WhenEvent[t > time1, a[t] -> 1],
WhenEvent[t > time2, a[t] -> 0]}]
returns
{WhenEvent[t > time1$1064, a[t] -> 1],
WhenEvent[t > time2$1064, a[t] -> 0]}
I guess it has something to do with the attribute of the WhenEvent
?
Attributes[WhenEvent]
(* {HoldAll, Protected} *)
Is there anyway to force the local variables in WhenEvent
to be evaluated?
HoldAll
:Module[{a = 1}, Hold@a]
. $\endgroup$