- Inside the for loop there is no expressions depending on the index ‘i’. So the execution of above two line will continue 2000 times.
- Each time the loop executes, the value of ‘xnew’ and ‘xold’ keep on decreasing and after the for-loop execution value of ‘xnew’ and ‘xold’ becomes Zero.
Bifurcation Diagram of Logistic Equation -- Unnecessary Lines in Code?
5 views (last 30 days)
Show older comments
clear all, close all,clc
xvals=[];
for beta =0:0.01:4
beta
xold = 0.5;
for i = 1:2000
xnew = ((xold-xold^2)*beta);
xold = xnew;
end
xss = xnew;
for i = 1:1000;
xnew = ((xold-xold^2)*beta);
xold = xnew;
xvals(1,length(xvals)+1) = beta;
xvals(2,length(xvals)) = xnew;
if (abs(xnew-xss) < .001)
break
end
end
end
plot (xvals(1,:),xvals(2,:),'.')
Hello again,
I was following a youtube tutorial by Steve Brunton, (link:https://www.youtube.com/watch?v=_BvAkyuWhOI&t=395s),to create the bifurcation diagram of the logistic map, and I don' seem to understand what the purpose of this block of code is:
for i = 1:2000
xnew = ((xold-xold^2)*beta);
xold = xnew;
end
The next for loop I understand, but the one I quoted above does not make sense to me. Also, for the last loop (i = 1:1000), how/why did the length of the array change (we had to add one to the length) ?
Thank you in advance and thank you for your patience, as I am fairly new to numerical programming
0 Comments
Answers (1)
Guru Mohanty
on 15 Apr 2020
After debugging your code, it seems the section of code you mentioned is irreverent, because of following reasons.
for i = 1:2000
xnew = ((xold-xold^2)*beta);
xold = xnew
end
See Also
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!