Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Incomplete diagram!

Subject: Incomplete diagram!

From: Sanaa

Date: 12 Jul, 2013 12:32:20

Message: 1 of 3

Hi,
I have a problem that I wish to plot what is called a bifurcation diagram.
The map under study is given by
x_((n+1)r)= 1 - ru *x^2_(nr),
where r is a positive constant may take 0.1,0.2,...
ru is a positive parameter, and the time t runs from nr to (n+1)r, n=0,1,2,...

I have the matlab code
%%%%%%%%%

% define the vector of values that r takes
r_vec = [0.2];
% define the vector of colors, to plot the dat aof reach value of r in
% different color
color_vec = ['b'];

for rho = 0: 0.005: 2


% do a loop of values of r
for j = 1 : size(r_vec,2)
% define delay
r = r_vec(j);
% define coefficient rho
%rho = 0.5;
% define the number of deiscrete times in interval [k*r, (k+1)*r]
n = 10;
% define the nimber of iterations k = 1,.....,Nit
Nit = 1000;
% define the initial vector which is a vector of size n
x0 = 0.3*ones(1,n);
% define vectors x_next and x_previous
x_next = zeros(1,n);
x_previous = zeros(1,n);
time = zeros(1,n);

% initialize x_previous
x_previous = x0;
x_next = x_previous;
time = linspace(0,r,n);
    
  % set the figure details
    figure(1)
    xlabel('t')
    ylabel('x')
    %plot(time,x_next,'*')
    hold on
for i = 1:Nit
    
    x_next = 1 - rho*x_previous.^2;
    x_previous = x_next;
    time = linspace(i*r,(i+1)*r,n);
    
 end
 end


      plot(rho,x_next(1),'.', 'Color', char(color_vec(j)),'linewidth',10)
      
end

hold off
% save the figure
% print -depsc map.eps
%%%%
The code works but I am wondering why I don't get a complete picture of the diagram, it seems that it is divided into 2 parts!!!!
Any help please.

Subject: Incomplete diagram!

From: someone

Date: 12 Jul, 2013 15:50:14

Message: 2 of 3

"Sanaa" wrote in message <krot0k$q4g$1@newscl01ah.mathworks.com>...
> Hi,
> I have a problem that I wish to plot what is called a bifurcation diagram.
> The map under study is given by
> x_((n+1)r)= 1 - ru *x^2_(nr),
> where r is a positive constant may take 0.1,0.2,...
> ru is a positive parameter, and the time t runs from nr to (n+1)r, n=0,1,2,...
>
> I have the matlab code
> %%%%%%%%%
>
> % define the vector of values that r takes
> r_vec = [0.2];
> % define the vector of colors, to plot the dat aof reach value of r in
> % different color
> color_vec = ['b'];
>
> for rho = 0: 0.005: 2
>
>
> % do a loop of values of r
> for j = 1 : size(r_vec,2)
> % define delay
> r = r_vec(j);
> % define coefficient rho
> %rho = 0.5;
> % define the number of deiscrete times in interval [k*r, (k+1)*r]
> n = 10;
> % define the nimber of iterations k = 1,.....,Nit
> Nit = 1000;
> % define the initial vector which is a vector of size n
> x0 = 0.3*ones(1,n);
> % define vectors x_next and x_previous
> x_next = zeros(1,n);
> x_previous = zeros(1,n);
> time = zeros(1,n);
>
> % initialize x_previous
> x_previous = x0;
> x_next = x_previous;
> time = linspace(0,r,n);
>
> % set the figure details
> figure(1)
> xlabel('t')
> ylabel('x')
> %plot(time,x_next,'*')
> hold on
> for i = 1:Nit
>
> x_next = 1 - rho*x_previous.^2;
> x_previous = x_next;
> time = linspace(i*r,(i+1)*r,n);
>
> end
> end
>
>
> plot(rho,x_next(1),'.', 'Color', char(color_vec(j)),'linewidth',10)
>
> end
>
> hold off
> % save the figure
> % print -depsc map.eps
> %%%%
> The code works but I am wondering why I don't get a complete picture of the diagram, it seems that it is divided into 2 parts!!!!
> Any help please.

I don't have MATLAB installed on this computer, but from the above my guess is to move the statements:

  % set the figure details
    figure(1)
    xlabel('t')
    ylabel('x')
    %plot(time,x_next,'*')
    hold on

before your outer loop and see what happens. I suspect the statement "figure(1) is executed twice and that is why your diagram is divided into 2 parts (as you state). But this is just a guess!

Subject: Incomplete diagram!

From: Sanaa

Date: 12 Jul, 2013 21:38:08

Message: 3 of 3

"someone" wrote in message <krp8jm$lm$1@newscl01ah.mathworks.com>...
> "Sanaa" wrote in message <krot0k$q4g$1@newscl01ah.mathworks.com>...
> > Hi,
> > I have a problem that I wish to plot what is called a bifurcation diagram.
> > The map under study is given by
> > x_((n+1)r)= 1 - ru *x^2_(nr),
> > where r is a positive constant may take 0.1,0.2,...
> > ru is a positive parameter, and the time t runs from nr to (n+1)r, n=0,1,2,...
> >
> > I have the matlab code
> > %%%%%%%%%
> >
> > % define the vector of values that r takes
> > r_vec = [0.2];
> > % define the vector of colors, to plot the dat aof reach value of r in
> > % different color
> > color_vec = ['b'];
> >
> > for rho = 0: 0.005: 2
> >
> >
> > % do a loop of values of r
> > for j = 1 : size(r_vec,2)
> > % define delay
> > r = r_vec(j);
> > % define coefficient rho
> > %rho = 0.5;
> > % define the number of deiscrete times in interval [k*r, (k+1)*r]
> > n = 10;
> > % define the nimber of iterations k = 1,.....,Nit
> > Nit = 1000;
> > % define the initial vector which is a vector of size n
> > x0 = 0.3*ones(1,n);
> > % define vectors x_next and x_previous
> > x_next = zeros(1,n);
> > x_previous = zeros(1,n);
> > time = zeros(1,n);
> >
> > % initialize x_previous
> > x_previous = x0;
> > x_next = x_previous;
> > time = linspace(0,r,n);
> >
> > % set the figure details
> > figure(1)
> > xlabel('t')
> > ylabel('x')
> > %plot(time,x_next,'*')
> > hold on
> > for i = 1:Nit
> >
> > x_next = 1 - rho*x_previous.^2;
> > x_previous = x_next;
> > time = linspace(i*r,(i+1)*r,n);
> >
> > end
> > end
> >
> >
> > plot(rho,x_next(1),'.', 'Color', char(color_vec(j)),'linewidth',10)
> >
> > end
> >
> > hold off
> > % save the figure
> > % print -depsc map.eps
> > %%%%
> > The code works but I am wondering why I don't get a complete picture of the diagram, it seems that it is divided into 2 parts!!!!
> > Any help please.
>
> I don't have MATLAB installed on this computer, but from the above my guess is to move the statements:
>
> % set the figure details
> figure(1)
> xlabel('t')
> ylabel('x')
> %plot(time,x_next,'*')
> hold on
>
> before your outer loop and see what happens. I suspect the statement "figure(1) is executed twice and that is why your diagram is divided into 2 parts (as you state). But this is just a guess!

Thanks a lot for your reply. Howerver, I didn't get any figure al all!!!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us