How can I plot a graph for only one eigen value against a variable? I'm only getting one M!

I am trying to plot a graph for k:[0,1] against the larger eigenvalue from the corresponding matrix. i.e for each value of k I am only interested in the larger of the two eigenvalues from the 2x2 matrix M.
This is a very basic code, I know, but having played around with it for a few days now I could really use some help!
% code
A=3.3;
B=0.45;
a=B;
b=((A+sqrt(A^2-4*B^2))/(2*B))^2;
c=-2*B;
d=-1-b;
D=500;
for k=0.0:0.01:1.0
M=[a-k^2 b; c d-D*k^2];
lam=eig(M);
end
plot(k,lam)
end

 採用された回答

Akira Agata
Akira Agata 2017 年 2 月 17 日
編集済み: Akira Agata 2017 年 2 月 17 日
I have slightly modified your code. I hope this will help!
A=3.3;
B=0.45;
a=B;
b=((A+sqrt(A^2-4*B^2))/(2*B))^2;
c=-2*B;
d=-1-b;
D=500;
k = (0:0.01:1);
lam = zeros(2,length(k));
for kk = 1:length(k)
M=[a-k(kk)^2 b; c d-D*k(kk)^2];
lam(:,kk)=eig(M);
end
plot(k,lam)

3 件のコメント

Jessica Wilcox
Jessica Wilcox 2017 年 2 月 17 日
Thank you for your comment. This produces a graph, but for both eigenvalues. What I am trying to do is plot only the larger of each eigenvalue, and wondered if there is a simple way to do this. Thanks again.
Yes, that's a piece of cake!
Let me slightly modify the code again.
A=3.3;
B=0.45;
a=B;
b=((A+sqrt(A^2-4*B^2))/(2*B))^2;
c=-2*B;
d=-1-b;
D=500;
k = (0:0.01:1);
lam = zeros(1,length(k));
for kk = 1:length(k)
M=[a-k(kk)^2 b; c d-D*k(kk)^2];
lam(kk)=max(eig(M));
end
plot(k,lam)
Now, you can obtain a plot only the larger eigenvalue as a function of k.
Jessica Wilcox
Jessica Wilcox 2017 年 2 月 23 日
Thank you, I have only just seen your reply - I had managed to work this bit out on my own but couldnt have gotten there without your edit, thank you!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by