for loop showing only last iteration and the graph shows dotted instead of lines
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
akhil rous
am 5 Jun. 2020
Kommentiert: akhil rous
am 15 Jun. 2020
clc
close all
clear
syms x y E
v=[x y];
J=jacobian([y,E*(1-x^2)*y-x], v);
p=[0 0];
j=subs(J,v,p);
a=-8:0.1:8;
for E=a
e = eig(j);
c=subs(e,E);
u=double(c);
plot(E,real(u),'.'); hold on
end
i'm new to matlab and i scripted the above code from various helps online, in order to find the bifurcation but i can't get a line plot where all the dots are combined and i have tried changing the '.' to '-' but still doesn't work.
Also i need every iteration of u on the workspace, currently it's just showing only the last iteration value
Thank you.
0 Kommentare
Akzeptierte Antwort
David Hill
am 5 Jun. 2020
clc
close all
clear
syms x y E
v=[x y];
J=jacobian([y,E*(1-x^2)*y-x], v);
p=[0 0];
j=subs(J,v,p);
a=-8:0.1:8;
for E=1:length(a)
e = eig(j);
c=subs(e,a(E));
b=double(c);
u(E)=b(1)+1i*b(2);%just guessing (did you expect a complex number)
end
plot(a,real(u),'Marker','*','MarkerSize',1);
5 Kommentare
David Hill
am 11 Jun. 2020
Primarily, you just want to load all the data into matrix c in the loop before plotting it all at once outside the loop. If you plot single points, you cannot connect lines to them and you cannot see them without markers. Since matrix c has two columns of complex numbers that you want plotted, c(:,1) plots the first column and c(:,2) plots the second column with respect to a (I used the same color 'b'). It is better to use an index into vector (a) and to index matrix (c) than to have the for-loop go through all of (a) itself.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!