Simplifying a for loop
Show older comments
Hello, I'm trying to approximate the Feigenbaum constant by using the logistic map. I came up with a script that gives you the bifurcation parameters, as below:
for k=nl:nh
if abs(x(k,nit+1)-x(k,nit+1-2))<e
b(2)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-4))<e
b(3)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-8))<e
b(4)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-16))<e
b(5)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-32))<e
b(6)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-64))<e
b(7)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-128))<e
b(8)=a(k);
elseif abs(x(k,nit+1)-x(k,nit+1-256))<e
b(9)=a(k);
break
end
end
('nit' means number of iterations, and k is related to the parameter a (r in some references))
Now it seems obvious that there is a simpler representation of the above code, as the integers are just the first eight exponents of 2. But I just can't come up with one. Could somebody help me?
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!