3
$\begingroup$

I'd like to run Manipulate with 0<r<=4 that preserves the ListLinePlot of the recurrence table given with the colors shown. I'm looking to use the autorun feature in Manipulate to show how the plot varies with 0<r<=4.

(*Logistics Map Model*)
Clear[r, y0, k, NN]
r = 4; y0 = 0.1; NN = 100;
sol = RecurrenceTable[{y[k + 1] == r*y[k]*(1 - y[k]), y[0] == y0}, 
   y, {k, 0, NN}];
ListLinePlot[sol, PlotRange -> {{0, NN}, {0, 1}}, PlotStyle -> Green, 
 Mesh -> Full, MeshStyle -> Red] 

enter image description here

$\endgroup$

1 Answer 1

7
$\begingroup$

To make Manipulate, follows these steps.

  1. Decided which variables should be controlled.
  2. Make slides/menus/etc.. for each control variable.
  3. Write the Manipulate expression which access these variables.
  4. Add TrackedSymbols :> {...} and list the names of these control variables to help Manipulate know which to track when changed.

The structure is like this

   Manipulate[
     expression goes here....last line must end by a comma.
     expression can be a whole module, or just sequence of
     commands. The last line is what you want updated on
     the screen when you change any control variable. This
     is typically a Plot or a Graphics. 
     ,
     control variables go here each separated by a comma
     
     additional Manipulate configurations goes here, such
     TrackedSymbols, Initialization section, etc... see help
  ]

Here is your code in Manipulate

   Manipulate[
     Module[{y0, NN, sol, y, k},
      y0 = 0.1; NN = 100;
      sol = RecurrenceTable[{y[k + 1] == r*y[k]*(1 - y[k]), y[0] == y0}, 
    y, {k, 0, NN}]; 
     ListLinePlot[sol, PlotRange -> {{0, NN}, {0, 1}}, 
     PlotStyle -> Green, Mesh -> Full, MeshStyle -> Red]
    ]
     ,
     {{r, 3, "r"}, 0, 4, .01, Appearance -> "Labeled"},
     TrackedSymbols :> {r}
     ]

enter image description here

$\endgroup$
1
  • $\begingroup$ Nasser: Thank you very much ... the structure you show to code Manipulate is very helpful ... thanks again .. prg $\endgroup$
    – user42700
    Sep 5, 2021 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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