matlabdiscrete-space

Matlab : Phase space plot


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)

Solution

  • 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).