mmamathes
(Bill Blair)
December 26, 2025, 4:48am
1
RecurrenceTable[{a[1] == 1, a[n + 1] == a[n] - a[n]^2/3},
a, {n, 100}][[-1]]
Why are both code snippets below running so slowly when calculating the 100th term? They’ve been running for a long time without any results. How can I fix this?
Nest[# - #^2/3 &, 1, 99]
Try:
RecurrenceTable[{a[1] == 1.0, a[n + 1] == a[n] - a[n]^2/3}, a, {n, 100}][[-1]] // AbsoluteTiming
(*{0.0003556, 0.0283592}*)
A[1] := 1.0;
A[n_] := A[n] = A[n - 1] - A[n - 1]^2/3;
A[100] // AbsoluteTiming
(*{0.0007379, 0.0283592}*)
I suppose that the calculation is slow because the a[n] are rational numbers of very rapidly increasing complication:
Map[ByteCount,
RecurrenceTable[{a[1] == 1, a[n + 1] == a[n] - a[n]^2/3},
a, {n, 20}]]