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

조회 수: 2 (최근 30일)
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.

채택된 답변

David Hill
David Hill 2020년 6월 5일
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
David Hill
David Hill 2020년 6월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by