Simplifying a for loop
显示 更早的评论
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?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!