# WhenEvent for RecurrenceTable

RecurrenceTable is like NDSolve for difference equations, but lacks a lot of its bells and whistles. One thing I'd like to use in RecurrenceTable is WhenEvent. Is there an easy way to achieve this?

For example, something like

RecurrenceTable[{x[t + 1] == 3 x[t] (1 - x[t]), x[0] == 0.1,
WhenEvent[x[t] > x[t - 1] && x[t + 1] > x[t], Print["max"]]}, x, {t, 0, 10}]


would detect local maxima, but this is just one potential application among many.

• For the specific example, use FindPeaks on the output of RecurrenceTable Oct 8 '17 at 21:08
• One way might be to write a function that looks like it does WhenEvent, from the outside, but actually just computes the recurrence table and then operates on the output with something like If[#2 > #1 && #2 > #3, Print[#2]] & @@@ Partition[rt, 3, 1];. It might get the convenience, but wouldn't actually be doing anything like the same thing (so StopIntegration wouldn't happen, although you could just return the output truncated to make it look like it stopped). Oct 8 '17 at 22:09
• Good thoughts on that example. Any ideas on how to achieve “StopIntegration” or how to change DiscreteVariables? Oct 9 '17 at 1:02

You could use Nest/NestList and identify yourself, e.g.:
r[n_, fu_] := fu[3 # (1 - #) &, 0.1, n]