for loop showing only last iteration and the graph shows dotted instead of lines

4 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

David Hill
David Hill el 5 de Jun. de 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 comentarios
David Hill
David Hill el 11 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by