Manipulate the first value of a recursive function, redraw plot


I'm new to this, casually executing basic lines of code online in Wolfram Lab; and I have a question I couldn't figure myself.

Example; I have a recursive function and its initial value

f[0] = 2

I can draw the connecting plot for the initial value:

ListPlot[Table[f[t], {t, 0, 100}], Joined -> True]

I would like to know how can I manipulate f[0]=k and redraw the plot as I move the slider:

Manipulate[f[0]=k, {k, 0, 10, 1}]

Can you then nest multiple plots of this same kind on the same graph in colors, each having their own $k_1,k_2,k_3\dots$ sliders?


Posted 2017-06-29T20:21:15.467

Reputation: 554

1Manipulate[f[x_] := Log[Abs[f[x - 1]]]; f[0] = k; ListPlot[Table[f[t], {t, 0, 100}], Joined -> True], {k , 0, 2}]? – kglr – 2017-06-29T20:32:19.413

@kglr That seems to work for a moment but ends up collapsing; Instead of a graph I see a red rectangle in the white area under the slider. – Vepir – 2017-06-29T20:42:36.677



Use RecurrenceTable with vector initial values {k1, k2, k3, k4}:


Manipulate[ListLinePlot[Transpose@RecurrenceTable[{f[x] == Log[Abs[f[x - 1]]], 
  f[0] == {k1, k2, k3, k4}}, f, {x, 1, 40}], PlotRange -> {-5, 5}], 
 {{k1, 2}, 2, 10}, {{k2, 2}, 2, 10}, {{k3, 2}, 2, 10}, {{k4, 2}, 2, 10}]

Mathematica graphics


Posted 2017-06-29T20:21:15.467

Reputation: 302 076

Thanks. Thought it collapsing must have something to do with Wolfram Lab itself I think. It randomly switches me from "Use as a deployable object instead" and "Use as a manipulate expression instead", and sometime just collapses either way. – Vepir – 2017-06-29T20:54:58.760

Vepir, thank you for the accept. Welcome to – kglr – 2017-06-29T20:55:47.950


I'm going to recommend a somewhat different approach, just in my own style. I hope it is helpful, despite kglr already offering a suitable work up.


This makes use of memoization and also gives us a chance to make use of the function in other ways if we want, e.g.

(* Output= Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[k0]]]]]]]]]]]]]] *)
(* Output= {1.09861,0.0940478,-2.36395,0.860335,-0.150434,-1.89423} *)

Screen capture:

Image of Wolfram Programming Lab Session Using Code Above

Kellen Myers

Posted 2017-06-29T20:21:15.467

Reputation: 2 558

I appreciate this :) – Vepir – 2017-06-30T12:42:18.493