Why do two functions in my plot "switch" positions when plotted?

1 回表示 (過去 30 日間)
Donald
Donald 2015 年 9 月 25 日
編集済み: Walter Roberson 2015 年 9 月 25 日
Here is my code:
clear
clc
m1 = 1;
m2 = 2;
m3 = 1;
k1 = 2000:8000;
k2 = 2000;
k3 = 6000;
M = [ m1 0 0; 0 m2 0; 0 0 m3]
for n = 1:length(k1);
K = [k1(n)+k2 -k2 0; -k2 k2+k3+3 -k3; 0 -k3 k3];
EV = eig(-inv(M)*K);
w1(n) = sqrt(abs(EV(1)));
w2(n) = sqrt(abs(EV(2)));
w3(n) = sqrt(abs(EV(3)));
end
figure(1)
plot(k1,w1/(2*pi),k1,w2/(2*pi),k1,w3/(2*pi))
legend w1 w2 w3
title('Varying k1')
ylabel('Frequency (Hz)')
xlabel('k1')
my plot looks like the picture attached. I cannot figure out why w2 and w3 seem to jump to one another after about 7000.
How can I resolve this?

採用された回答

Steven Lord
Steven Lord 2015 年 9 月 25 日
EIG doesn't guarantee it always returns the eigenvalues in any particular order. If you want them to always be returned in increasing order or always in decreasing order, SORT them.
  1 件のコメント
Donald
Donald 2015 年 9 月 25 日
I'm not too familiar with using the EIG function, after going back and using the sort function to obtain the correct corresponding eigenvalues, the plot was fixed.
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by