8
$\begingroup$

Bug introduced in 10.0 or earlier and persisting through 12.2 or later

The output of RecurrenceTable seems to lose a level when there are more than 250 points and one variable. Easiest to explain with an example:

Good:

RecurrenceTable[{n[t + 1] == 2 (1 - n[t]) n[t], n[0] == 0.1}, {n}, {t, 0, 249}]

(* {{0.1}, {0.18}, {0.2952}, {0.416114}, {0.485926}, {0.499604}, {0.5}, {0.5}, ... {0.5}} *)

Bad:

RecurrenceTable[{n[t + 1] == 2 (1 - n[t]) n[t], n[0] == 0.1}, {n}, {t, 0, 250}]

(* {{0.1}, 0.18, 0.2952, 0.416114, 0.485926, 0.499604, 0.5, 0.5, ... 0.5} *)

Having more than one variable works as expected:

RecurrenceTable[{n[t + 1] == 2 (1 - n[t]) n[t], m[t + 1] == 2 (1 - m[t]) m[t], n[0] == 0.1, m[0] == 0.1}, {n, m}, {t, 0, 250}]

(* {{0.1, 0.1}, {0.18, 0.18}, {0.2952, 0.2952}, {0.416114, 0.416114}, {0.485926, 0.485926}, {0.499604, 0.499604}, {0.5, 0.5}, {0.5, 0.5}, ... {0.5, 0.5}} *)

I've found a couple easy workarounds for this minimal example (e.g. use n instead of {n}, use NestList instead of RecurrenceTable), but I've got RecurrenceTable embedded in a general function that requires both a list of dependent variables and doesn't play well with NestList. I just wanted to see if others have this same issue, which I'll report to WRI. I'm using Mathematica 11.0.1 on MacOS 10.12.

$\endgroup$
2
  • 8
    $\begingroup$ It's a bug. For a workaround, try Method -> {Compiled -> False}. $\endgroup$
    – ilian
    Oct 10, 2016 at 15:53
  • $\begingroup$ @ilian Brilliant, thanks! $\endgroup$
    – Chris K
    Oct 10, 2016 at 16:05

1 Answer 1

3
$\begingroup$

@ilian's fix in comments above works fine: add Method -> {Compiled -> False}. I've also reported to WRI.

Edit: But you know what, compiling is kind of a nice feature, so another workaround is to post-process the results, like

Replace[
  RecurrenceTable[{n[t + 1] == 2 (1 - n[t]) n[t], n[0] == 0.1}, {n}, {t, 0, 250}],
  n_?NumericQ -> {n}, 1]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.