Soring varying and compex eigenvalues

5 views (last 30 days)
I have a linearized system "VariableKp" with a parameter variation "Kp". As the parameter vary, the eigenvalues of the system change. The objective is to see how the eigenvalues change as the parameter sweep is performed, meaning that the rows of "E" or "Q" should contain information about the same eigenvalue, and its development. The order of eigenvalues collected from the "eig" function is however random.
How can I sort these eigenvalues?
Simply using the "sort" command based on real/imag/abs does not work as the eigenvalues change during the parameter sweep.
The problem is illustrated in for example row 7/8 VS 11/12 in the last column in E.
[A,B,C,d] = ssdata(VariableKp); %112 order system.
for k=1:1:5 %Five variations of Kp
Q(:,k)=eig(VariableKp(:,:,k,1));
end
for k=1:1:5
[~,I]=sort(imag(Q(:,k)));
E(:,k) = Q(I,k);
end
E =
1.0e+03 *
-1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i
-1.0625 - 1.9385i -1.0625 - 1.9390i -1.0625 - 1.9390i -1.0625 - 1.9390i -1.0625 - 1.9390i
-0.0451 - 0.7707i -0.0451 - 0.7707i -0.0451 - 0.7707i -0.0451 - 0.7707i 0.2732 - 0.8849i
-0.0434 - 0.7697i -0.0434 - 0.7702i -0.0434 - 0.7702i -0.0434 - 0.7702i 0.2732 - 0.8849i
-0.0390 - 0.7565i -0.0390 - 0.7565i -0.0390 - 0.7565i -0.0390 - 0.7565i 0.2732 - 0.8849i
-0.0371 - 0.7555i -0.0371 - 0.7560i -0.0371 - 0.7560i -0.0371 - 0.7560i 0.2732 - 0.8849i
-1.8911 - 0.6294i -1.8911 - 0.6294i -1.8911 - 0.6294i -1.8911 - 0.6294i -0.0451 - 0.7707i % 7
-1.8959 - 0.6249i -1.8959 - 0.6254i -1.8959 - 0.6254i -1.8959 - 0.6254i -0.0434 - 0.7702i % 8
-0.0697 - 0.0545i -0.0697 - 0.0545i -0.0697 - 0.0545i 0.0024 - 0.1147i -0.0390 - 0.7565i
-0.0697 - 0.0545i -0.0697 - 0.0545i -0.0697 - 0.0545i 0.0024 - 0.1147i -0.0371 - 0.7560i
-0.0698 - 0.0544i -0.0698 - 0.0544i -0.0698 - 0.0544i 0.0024 - 0.1147i -1.8911 - 0.6294i % should be 7
-0.0698 - 0.0544i -0.0698 - 0.0544i -0.0698 - 0.0544i 0.0024 - 0.1147i -1.8959 - 0.6254i % should be 8
....................................
Q =
1.0e+03 *
-1.0625 + 1.9385i -1.0625 + 1.9390i -1.0625 + 1.9390i -1.0625 + 1.9390i -1.0625 + 1.9390i
-1.0625 - 1.9385i -1.0625 - 1.9390i -1.0625 - 1.9390i -1.0625 - 1.9390i -1.0625 - 1.9390i
-1.0594 + 1.9406i -1.0594 + 1.9406i -1.0594 + 1.9406i -1.0594 + 1.9406i -1.0594 + 1.9406i
-1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i -1.0594 - 1.9406i
-1.8959 + 0.6249i -1.8959 + 0.6254i -1.8959 + 0.6254i -1.8959 + 0.6254i -1.8959 + 0.6254i
-1.8959 - 0.6249i -1.8959 - 0.6254i -1.8959 - 0.6254i -1.8959 - 0.6254i -1.8959 - 0.6254i
-1.8911 + 0.6294i -1.8911 + 0.6294i -1.8911 + 0.6294i -1.8911 + 0.6294i -1.8911 + 0.6294i
-1.8911 - 0.6294i -1.8911 - 0.6294i -1.8911 - 0.6294i -1.8911 - 0.6294i -1.8911 - 0.6294i
-0.0434 + 0.7697i -0.0434 + 0.7702i -0.0434 + 0.7702i -0.0434 + 0.7702i -0.0434 + 0.7702i
-0.0434 - 0.7697i -0.0434 - 0.7702i -0.0434 - 0.7702i -0.0434 - 0.7702i -0.0434 - 0.7702i
-0.0371 + 0.7555i -0.0371 + 0.7560i -0.0371 + 0.7560i -0.0371 + 0.7560i -1.5546 + 0.0000i
-0.0371 - 0.7555i -0.0371 - 0.7560i -0.0371 - 0.7560i -0.0371 - 0.7560i -1.5546 + 0.0000i
................................

Accepted Answer

Christine Tobler
Christine Tobler on 25 Jan 2021
This can't be done one the level of individual EIG calls, since it's necessary to track eigenvalues from one call to the next. Take a look at the File Exchange package Eigenshuffle, which takes a set of matrices and orders the eigenvalues for each matrix so that the match the eigenvalues of the previous matrix as closely as possible. Note that I think this relies on one parameter being varied, if you are varying several parameters you may have to get more creative.
  2 Comments
Johannes Silde
Johannes Silde on 26 Jan 2021
Thank you for your answer.
The Eigenshuffle function sorts the eigenvalues better than my original code, but not perfectly. This is shown in the result below, both in the figure and in the numbers. Especially the values within the circle seems like an obvious sloppy error. Might it be possible to for-example increase accuracy by increasing the running time?
[A,B,C,d] = ssdata(VariableKp);
[Vseq,Dseq] = eigenshuffle(A);
Dseq=
1.0e+03 *
.........................
-0.0008 + 0.0006i -0.0008 + 0.0006i -0.0010 + 0.0029i -0.0010 + 0.0029i -0.0010 + 0.0029i
-0.0008 - 0.0006i -0.0008 - 0.0006i -0.0010 - 0.0029i -0.0010 - 0.0029i -0.0010 - 0.0029i
-0.0009 + 0.0029i -0.0009 + 0.0029i -0.0066 + 0.0082i -0.0065 + 0.0083i -0.0065 + 0.0083i % Three last
-0.0009 - 0.0029i -0.0009 - 0.0029i -0.0040 - 0.0108i 0.0024 + 0.1147i 0.2732 + 0.8849i
-0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i
-0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i
-0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i
-0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i
-0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i
-0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i
-0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i -0.0010 + 0.0001i
-0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i -0.0010 - 0.0001i
-0.0013 + 0.0018i -0.0013 + 0.0018i -0.0014 + 0.0018i -0.0014 + 0.0018i -0.0014 + 0.0018i
-0.0013 - 0.0018i -0.0013 - 0.0018i -0.0014 - 0.0018i -0.0014 - 0.0018i -0.0014 - 0.0018i
-0.0018 + 0.0028i -0.0018 + 0.0028i -0.0040 + 0.0108i 0.0024 + 0.1147i 0.2732 + 0.8849i
-0.0018 - 0.0028i -0.0018 - 0.0028i -0.0052 - 0.0106i -0.0052 - 0.0114i -0.0052 - 0.0114i
-0.0018 + 0.0027i -0.0018 + 0.0027i -0.0018 + 0.0027i -0.0018 + 0.0027i -0.0018 + 0.0027i
-0.0018 - 0.0027i -0.0018 - 0.0027i -0.0018 - 0.0027i -0.0018 - 0.0027i -0.0018 - 0.0027i
-0.0047 + 0.0000i -0.0047 + 0.0000i -0.0047 + 0.0000i -0.0047 + 0.0000i -0.0047 + 0.0000i
-0.0050 + 0.0000i -0.0050 + 0.0000i -0.0050 + 0.0000i -0.0050 + 0.0000i -0.0050 + 0.0000i
-0.0051 + 0.0114i -0.0051 + 0.0114i -0.0051 + 0.0108i -0.0054 + 0.0116i -0.0054 + 0.0116i
-0.0051 - 0.0114i -0.0051 - 0.0114i -0.0042 - 0.0116i 0.0024 - 0.1147i 0.2732 - 0.8849i
-0.0053 + 0.0117i -0.0053 + 0.0117i -0.0044 + 0.0117i 0.0024 - 0.1147i 0.2732 - 0.8849i
-0.0053 - 0.0117i -0.0053 - 0.0117i -0.0044 - 0.0117i 0.0024 + 0.1147i 0.2732 + 0.8849i
-0.0064 + 0.0082i -0.0064 + 0.0082i -0.0052 + 0.0106i -0.0052 + 0.0114i -0.0052 + 0.0114i % Three last
-0.0064 - 0.0082i -0.0064 - 0.0082i -0.0066 - 0.0082i -0.0065 - 0.0083i -0.0065 - 0.0083i
........................................
Christine Tobler
Christine Tobler on 26 Jan 2021
I don't know much about the internal workings of eigenshuffle, so I'm not sure about this. You might add a comment in the FileExchange page for eigenshuffle.
Otherwise, if you're up for trying to write something on your own, you might have a look at the matchpairs function, which maps one set of points to another set of points, given a matrix M where M(i, j) contains the distance between point x(i) and point y(j). In your case, this would be M = abs(E(:, k-1) - E(:, k).').
For the second input costUnmatched for matchpairs, I would just choose a value that's about 10 times as large as the largest eigenvalue - that should force matchpairs to try to match each value up with another, no matter how far apart they are.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!