1
$\begingroup$

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[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?

$\endgroup$
  • 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
1
$\begingroup$

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

ClearAll[f]

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

$\endgroup$
  • $\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
1
$\begingroup$

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_][0]:=f[k0][0]=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][7]
(* Output= Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[Log[Abs[k0]]]]]]]]]]]]]] *)
N[f[3]/@Range[6]]
(* Output= {1.09861,0.0940478,-2.36395,0.860335,-0.150434,-1.89423} *)

Screen capture:

Image of Wolfram Programming Lab Session Using Code Above

$\endgroup$
  • $\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.