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?

  • 1
    $\begingroup$ Manipulate[f[x_] := Log[Abs[f[x - 1]]]; f[0] = k; ListPlot[Table[f[t], {t, 0, 100}], Joined -> True], {k , 0, 2}]? $\endgroup$
    – kglr
    Jun 29 '17 at 20:32
  • $\begingroup$ @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. $\endgroup$
    – Vepir
    Jun 29 '17 at 20:42

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

  • $\begingroup$ 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. $\endgroup$
    – Vepir
    Jun 29 '17 at 20:54
  • $\begingroup$ Vepir, thank you for the accept. Welcome to mma.se. $\endgroup$
    – kglr
    Jun 29 '17 at 20:55

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

  • $\begingroup$ I appreciate this :) $\endgroup$
    – Vepir
    Jun 30 '17 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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