1
$\begingroup$

I am trying to simulate Logisticmap equation(xn+1 = r*xn(1 − xn)) for two very slightly different initial conditions and compare them after N iterations. This code works fine, but for very very nearby Initial conditions it is difficult to see how the path trajectories deviate. So I only want to show last five iterations in a single frame as the manipulation animation plays. The code I am using is as follows:

rinput = 3.6;
xin1 = 0.9;
xin2 = 0.9000000001;
r = rinput;
xiter = 500;
x1[0] = xin1;
x2[0] = xin2;
min = 1;
max = 200;
For[n = 1, n <= xiter, n++,
 x1[n] = r*x1[n - 1]*(1 - x1[n - 1]);
 x2[n] = r*x2[n - 1]*(1 - x2[n - 1]);
 ]
rt1 = Table[{n, x1[n]}, {n, min, max}];
rt2 = Table[{n, x2[n]}, {n, min, max}];
lst = Table[Take[rt1, n], {n, 1, Length[rt1]}];
lst2 = Table[Take[rt2, n], {n, 1, Length[rt2]}];
Manipulate[
 Show[ListLinePlot[lst[[n]], PlotRange -> {0, 1}, 
    PlotStyle -> {Black}, Joined -> True] /. Line -> Arrow, 
  ListLinePlot[lst2[[n]], PlotRange -> {0, 1}, Joined -> True, 
    PlotStyle -> {Red}] /. Line -> Arrow], {n, min, max, 1}] 
$\endgroup$
2
  • $\begingroup$ rinput isn't defined yet. Perhaps RSolve might be a helpful function . $\endgroup$ Feb 22, 2023 at 10:58
  • $\begingroup$ sorry! I forgot to add that in the question I will correct it. I have defined it in my program. $\endgroup$ Feb 24, 2023 at 9:13

1 Answer 1

1
$\begingroup$

You don't need the variables lst and lst2. Given a list l, if you want the elements between indices i and j, you can write l[[i ;; j]]. Also, you can combine your two ListLinePlot into a single one. That gives you:

Manipulate[
 ListLinePlot[{rt1[[n ;; n + 5]], rt2[[n ;; n + 5]]}, 
   PlotStyle -> {Black, Red}, Joined -> True] /. Line -> Arrow, {n, 
  min, max - 5, 1}]
$\endgroup$

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .