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.
akhil rous
akhil rous 2020 年 6 月 15 日
Thanks bro!!!
It really helped.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by