2
$\begingroup$

Suppose I have a 2-dimensional map $x_{n+1} = f(x_{n},y_{n}), \quad y_{n+1} = g(x_{n},y_{n})$, and a number of initial points $(x_{0}, y_{0})$ in some given range. I take each initial point and iterate the map a certain number of times. How do I generate a list of all the results and a phase portrait that shows all the iterates of all the initial condition?

For example, take $x_{n+1} = x_{n} + 2y_{n}, \quad y_{n+1} = y_{n}$ with $x_{0} \in [1,3]$ and $y_{0} \in [2,5]$, with these intervals partitioned with a step size of $0.2$ and, therefore, I have $150$ initial points.

I assume I should use RecurrenceTable and ListPlot, but beyond that I'm stuck.

$\endgroup$
1
$\begingroup$

NestList is built for this kind of thing. Define f and g:

f[x_, y_] := x + 2 y
g[x_, y_] := y

Then you can generate all your initial points with

Flatten[Table[{i, j}, {i, 1, 3, 0.2}, {j, 2, 5, 0.2}], 1]

(* {{-0.5, -0.5}, {-0.5, -0.4}, {-0.5, -0.3}, ...,
    {0.5, 0.3}, {0.5, 0.4}, {0.5, 0.5}} *)

NestList can get you the iterates for an initical point, and you can Map (/ @) that over the list of inital points to get all the iterates:

points = NestList[{f[#[[1]], #[[2]]], g[#[[1]], #[[2]]]} &, #, 100] & /@ 
   Flatten[Table[{i, j}, {i, 1, 3, 0.2}, {j, 2, 5, 0.2}], 1];

ListPlot[points]

enter image description here

Notice that the iterated from each initial point are coloured differently by ListPlot.

Using the Duffing map for another example:

f[x_, y_] := y
g[x_, y_] := -0.2 x + 2.75 y - y^3
points = NestList[{f[#[[1]], #[[2]]], g[#[[1]], #[[2]]]} &, #, 1000] & /@ 
   Flatten[Table[{i, j}, {i, -0.5, 0.5, 0.1}, {j, -0.5, 0.5, 0.1}], 1];
ListPlot[Flatten[points, 1]]

enter image description here

If you want to get rid of transients -- which is often the case -- you can simply Drop the first n points to obtain a cleaner plot:

points = Drop[
     NestList[{f[#[[1]], #[[2]]], g[#[[1]], #[[2]]]} &, #, 1000], 
     100] & /@ 
   Flatten[Table[{i, j}, {i, -0.5, 0.5, 0.1}, {j, -0.5, 0.5, 0.1}], 1];
ListPlot[Flatten[points, 1]]

enter image description here

$\endgroup$

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.