Plotting bifurcation diagram for Henon Map

I'm trying to plot the bifurcation diagram for the Henon map but when I try to vary the a values in the code I get an error. ''In an assignment A(I) = B, the number of elements in B and I must be the same.''When I replace the line a = 0:0.01:2; with a equal to any one value eg. a= 1.4, it plots all the x values at that a just fine. Any idea on how to fix the error? Thanks
clear all
close all
%Number of Iterations
N = 100;
%Initial Conditions
X(1)=0;
Y(1)=0.1;
a = 0:0.01:1.5;
for i=2:N
X(i)= Y(i-1)+ 1 - a*(X(i-1))^2;
Y(i) = .3*X(i-1);
plot(a,X,'.b','MarkerSize',2);
xlabel('a','FontWeight', 'Bold'), ylabel('x','FontWeight', 'Bold')
end

Answers (2)

Reading this page you can see that the parameters a and b are just two values, your a is a vector so it doesn't work properly, doing X(i)= you expect just one value to be in that index position but the calculation results in several values so it fails.
Stealing the code from the page you can see how it does work.
function Henon_map(a,b)
%This function takes in the alpha and beta values for the Henon map and
%iterates (0.1,0) 6000 times. It disregards the first 50 iterates and
%graphs the rest in the Cartesian plane.
N=6000;
x=zeros(1,N);
y=zeros(1,N);
x(1)=0.1;
y(1)=0;
for i=1:N
x(i+1)=1+y(i)-a*(x(i))^2;
y(i+1)=b*x(i);
end
axis([-1,2,-1,1])
plot(x(50:N),y(50:N),'.','MarkerSize',1);
fsize=15;
set (gca,'xtick',[-1:1:1],'FontSize',fsize)
set (gca,'ytick',[-1:1:2],'FontSize',fsize)
xlabel('\itx','FontSize',fsize)
ylabel('\ity','FontSize',fsize)
end

1 Comment

Yes sorry I realise now that a is a vector and the code can only take single values.
The code that you posted back produces the Henon attractor (Y versus X) but I want to plot a diagram of a against X. Thats why I need to be able to vary a. Is there any way I can alter the X(i) = line so that it will take a vector instead of single values?
Thanks

Sign in to comment.

If "a" is a vector, then a*(X(i-1))^2 is going to be a vector, so Y(i-1)+ 1 - a*(X(i-1))^2 would be a vector -- which you then promptly try to store in the single slot X(i)
We cannot tell you how to "fix" this problem because you have accidentally chopped out all of your comments about what your loop is intended to do.
For example it is not clear as to what your purpose is in creating all of those plots and erasing them all again (except the last) before the user has a chance to see them. Perhaps you also accidentally chopped out your "hold" call ?

2 Comments

Yes I'm sorry, I did erase the hold call by accident when posting the question.
My loop is intended to create 100 iterations of X at each value of a (where a varies from 0 to 1.5 in intervals of 0.01). So my problem is I can't vary a because it then becomes a vector?
a = 0:0.01:1.5;
num_a = length(a);
X = zeros(num_a, N);
Y = zeros(num_a, N);
Y(:,1) = 0.1;
for i=2:N
X(:,i)= Y(:,i-1)+ 1 - a.*(X(:,i-1))^2;
Y(:,i) = .3*X(:,i-1);
end

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Asked:

on 16 Aug 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!