Plotting bifurcation diagram for Henon Map
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Paulo Silva
on 16 Aug 2011
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.
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
Walter Roberson
on 16 Aug 2011
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
Walter Roberson
on 17 Aug 2011
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
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!