# 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[x_]:=Log[Abs[f[x-1]]]
f = 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=k and redraw the plot as I move the slider:

Manipulate[f=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?

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

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

ClearAll[f]

Manipulate[ListLinePlot[Transpose@RecurrenceTable[{f[x] == Log[Abs[f[x - 1]]],
f == {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}] • 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. Jun 29 '17 at 20:54
• Vepir, thank you for the accept. Welcome to mma.se.
– 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.

f[k0_][x_]:=f[k0][x]=Log[Abs[f[k0][x-1]]]
f[k0_]:=f[k0]=k0
Manipulate[
ListPlot[
Transpose[Table[{f[k1][x],f[k2][x],f[k3][x],f[k4][x]},{x,0,10,1}]],
Joined->True
],
{{k1,2},2,10},{{k2,3},2,10},{{k3,4},2,10},{{k4,5},2,10}
]


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.

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


Screen capture: • I appreciate this :) Jun 30 '17 at 12:42