Matlab getting incredibely slow when plotting
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I'm working on a bifurcation diagram plotting project.
I've written two very similar codes for that, one is plotting the logistic, the other one the Gauss iterative map.
Although the two codes are very similar, the first one (logistic) finishes plotting in 10 seconds, meanwhile it takes 50 seconds for Matlab to plot the Gauss one, and it often freezes after that and the figure can't be closed. I couldn't find a real difference between the codes, what might be the issue with the Gauss one?
Here are the scripts:
Logistic:
Resolution = 100000;
Transients = 512;
SavedPoints = 128;
r = linspace(0,4,Resolution);
x = 0.5*ones(1,Resolution);
% Transient iterations v1
tic
for i=1:Resolution
for j=1:Transients
x(i) = r(i)*x(i)*(1-x(i));
end
end
toc
figure(2); hold on;
for i=1:SavedPoints
for j=1:Resolution
x(j) = r(j)*x(j)*(1-x(j));
end
p2=plot(r,x);
set(p2,'LineStyle','none','Marker','.','MarkerSize',0.5,'Color',[0 0 0]);
end
The Gauss:
Resolution=1000;
%a=linspace(0,5,N+1);
a=4.90;
b=linspace(-1,1,Resolution);
x=ones(Resolution);
T=512;
tic
for t=1:T
for i=1:Resolution
x(i)=exp(-1*a*x(i)^2)+b(i);
end
end
toc
SavedPoints=128;
figure(3); hold on;
tic
for it=1:SavedPoints
for i=1:Resolution
x(i)=exp(-1*a*x(i)^2)+b(i);
end
p2=plot(b,x);
set(p2,'LineStyle','none','Marker','.','MarkerSize',0.1,'Color',[0,0,0]);
end
toc
Thank you for your answers!
M
1 commentaire
Walter Roberson
le 24 Fév 2021
I would expect that exp() would be slower than multiplications.
I am still investigating on the graphics speed... I do see what you mean.
Réponses (1)
Walter Roberson
le 24 Fév 2021
For the first one you have
x = 0.5*ones(1,Resolution);
which is a row vector.
For the second one you have
x=ones(Resolution);
which is a square array.
3 commentaires
Walter Roberson
le 25 Fév 2021
It is not a matter of "optimization"
When you plot() a 2d array, one line is created for each column. So you were creating 1000 lines each plot() call, each with 1000 points. And you were doing that 128 times, so you were ending up with 128000 line objects of 1000 points each.
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!