Bifurcation Diagram of Logistic Equation -- Unnecessary Lines in Code?

3 vues (au cours des 30 derniers jours)
Maria Raheb
Maria Raheb le 10 Avr 2020
Commenté : Maria Raheb le 15 Avr 2020
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

Réponses (1)

Guru Mohanty
Guru Mohanty le 15 Avr 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
  1. Inside the for loop there is no expressions depending on the index ‘i’. So the execution of above two line will continue 2000 times.
  2. 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.
It would be helpful to run the code in Debug Mode.
  1 commentaire
Maria Raheb
Maria Raheb le 15 Avr 2020
Both for loops in the code do not depend on the index "i" though, so what makes that block of code different? Are you suggesting that that block of code be deleted from script?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by