2

I am a beginner into chaos and nonlinear dynamics. I was trying to plot the phase space plot for Tent Map using Matlab. A phase space plot is a plot of its independent variables. So, if a system has one variable, then it will be a plot of the previous vs the next value. The outline of the plot resembles the Tent Map, but I am getting several cross lines. The phase space plot should look like a triangle (hence the name Tent) bounded between zero and one. If the parameter is mu, then the highest value should be mu/2. The correct phase space plot should be

enter image description here

I tried for other discrete maps as well and getting similar lines. However in books and all, I have seen a clean curve with no lines as such. Where am I going wrong? Also, the plot does not start from zero in the X axis. This Question is from the perspective of programming and concepts as well. I do not know how to get the graph of x[n] vs x[n-1] as shown in the plot given in wikipedia.

Tent map

Here is the Matlab code for the Tent map, where the parameter mu = 2.

N = 256;
x(1) = rand();  % Initial condition

for j=2:N
    if (double(x(j-1)))>0 && (double(x(j-1)))<0.5        
        x(j)=2*x(j-1);                        
    elseif (double(x(j-1)))>=0.5                          
        x(j)=2*(1-x(j-1));                    
    end
end

for k = 2:N
    next(k) = x(k-1);
end

plot(next,x)
David
  • 8,449
  • 1
  • 22
  • 32
SKM
  • 959
  • 2
  • 19
  • 45
  • http://www.mathworks.com/matlabcentral/fileexchange/7370-chaotic-maps/content/cmaps/tenti.m gives an implementation but I is hard to follow and I am not getting the phase space plot which should be http://en.wikipedia.org/wiki/File:Tent_map.png – SKM May 03 '15 at 23:14
  • You should need to use `double`, `x` is created with `rand()` and should always be a `double` array. – David May 04 '15 at 01:01
  • The tent function is not the same as the tent map. Your first picture is the tent function, your second is the phase space plot of the tent map (with the correction that Hwathanie gave). – David May 04 '15 at 01:08
  • @David: Could you please mention the difference between the Tent function and the map? Are the Equations different? – SKM May 04 '15 at 16:18

2 Answers2

3

There are several problems in your code. First, your conditions are too complex, and casting something to double is unnecessary since that is Matlab's default data type anyway. Here's the cleaned-up code for the computation loop:

for j = 2 : N
    if x(j - 1) < 0.5        
        x(j) = 2 * x(j - 1);                        
    else  
        x(j) = 2 * (1 - x(j - 1));                    
    end
end

This can be made even simpler by using the formula given in the Wikipedia page:

for j = 2 : N
    x(j) = 2 * min(x(j - 1), 1 - x(j - 1));
end

Second, a simple plot command by default connects the points by lines; this is not what you want. Also, the extra loop to compute next is unnecessary. Simply use Matlab's vector generation and indexing capabilities:

plot(x(1 : end - 1), x(2 : end), '.')
axis equal
axis([0 1 0 1])

and you get

This is probably still not what you expected: the full tent map. That's because what you are computing is not the map itself, but a trajectory governed by the map, which consists of 256 points as you specified. Not every possible value for x out of [0, 1] can occur in these 256 steps, so you get just a few points on the map.

If you do not want to get points on the map, but a graph of the tent map itself, do this:

x = 0 :0.01: 1;
plot(x, 2 * min(x, 1 - x))
axis equal
axis([0 1 0 1])

Note that this is not a phase plot in the standard sense, which is a plot of the system state over time, nor a phase portrait, which describes the structure of phase space (and which does not really apply to maps).

A. Donda
  • 8,381
  • 2
  • 20
  • 49
  • Thank you for your reply. Could you please clarify the following details ? (1) You have mentioned that the second graph it is not a phase space plot of the Tent map. But the Text books and wikepedia says that it is the phase space graph, alternatively called the phase portrait. A trajectory is the plot of the variable w.r.t time. (2) What is the procedure for generating graph of the maps so that I can do that for other discrete maps such as Logistic etc. (3) What is the graph where I got extra lines, similar to what Hwathenie has mentioned, called? – SKM May 04 '15 at 16:24
  • @SKM, you're welcome. (1) The Wikipedia page does not even mention the word "phase", and the caption of the graphic you linked to says "tent map" and nothing more. I'm using the words "phase plot", "phase portrait", and "trajectory" in accordance with the use in Wikipedia, which is identical to the meaning of these words I learned when studying nonlinear dynamics. A quick check in [Scholarpedia](http://www.scholarpedia.org/article/Phase_space) confirms this use. What textbook do you use? – A. Donda May 04 '15 at 17:58
  • 1
    (2) A map is nothing more than a function from a given interval onto that same interval. Therefore maps are plotted in the same way as any other function of a variable. I normally use `plot` as demonstrated in the answer, but you can also have a look at `ezplot`. I would strongly recommend that you take the time to work through the sections *Language Fundamentals*, *Mathematics*, *Graphics*, and *Programming Scripts and Functions* of the Matlab documentation before going any further. Learning by doing only works after you have a solid foundation. – A. Donda May 04 '15 at 18:02
  • (3) I don't think there is a special name for that, except "programming error". ;-) I can't think of a context where connecting a sequence of pairs (x(j-1), x(j)) by lines makes any sense. – A. Donda May 04 '15 at 18:05
  • Thank you for your reply. I applied your code in generating the time series. I have initialized x(1) = rand() for generating the initial value. In some cases of I am getting the error mentioned by Hwathenie -- x(54) = 0.750000000000000 x(55) = 0.500000000000000 x(56)= 1 and the rest are all zero valued. How do I prevent / solve this? I am using the book Nonlinear Time Series Analysis, by Kantz. I believed the definition for phase space / portrait = plot of variables, for ex in Lorenz plot of x,y,z will give the butterfly phase portrait. Please correct me if wrong. – SKM May 04 '15 at 18:25
  • Actually you shouldn't prevent that; while the map in general produces chaotic dynamics, there are special initial conditions that lead to simple periodic orbits. Also consider that chaos only happens in continuous spaces, while the computer uses only a discrete approximation. Strictly speaking, there is no chaos in digital computer simulations. – A. Donda May 04 '15 at 18:39
  • The book by Kantz is good, though it focuses on time series analysis and so it could be useful to look at an introduction to nonlinear dynamics like those of Ott or Strogatz. But, I looked up the tent map in the book (2004 ed.), and it does not say anywhere that this plot is a phase plot or phase portrait. The closest thing to this is Fig. 11.1, and the caption says "return map", nothing more. Also, the tent map has only one variable and therefore a 1-dimensional phase space. The map describes the dynamics *in* this space; it is *not* a portrait of the phase space itself. – A. Donda May 04 '15 at 18:45
  • @SKM, as much as I like to help you: these comments have become far too long and too many. I can only say: Read carefully again the book, and figure out what *precisely* it says about maps, phase plots etc. – A. Donda May 04 '15 at 18:46
1

I executed your code with two simple changes, one clear all at the beginning and disp([j-1 x(j-1)]); inside for loop. Following is the last part of my output.

52.0000    0.7500
53.0000    0.5000
54     1
55     0
Attempted to access x(56); index out of bounds because numel(x)=55.
Error in phaseSpacePlot (line 10)
    disp([j-1 x(j-1)]);

Now it is easy to understand. Cos in you if else condition rule if double(x(j-1)))<=0 is not defined. Hence loop ends when that condition meets. I added = sign to your if condition as if (double(x(j-1)))>=0 && (double(x(j-1)))<0.5 and got the following graph. Code now works, but I am not sure it is mathematically correct or not.

enter image description here

Huá dé ní 華得尼
  • 1,248
  • 1
  • 18
  • 33
  • Thank you for pointing out the error; I was getting the same and did not know the cause. – SKM May 04 '15 at 16:25