How to make the positions of eigenvalues consistently in Mathematica

In summary, the value of eigenvalues are not consistent given by mathematica, but a quick fix might be to replace your matrix with a sort by abs[] that sorts in +- pairs. If you want in real part order then you can do {-a,-b,-c,c,b,a}
  • #1
kaizen.moto
98
0
Hi there,

Iam just wondering that at different values of m and n, the position of eigenvalues are always varies accordingly. I mean, the outputs positions of eigenvalues are not consistent given by mathematica.

Please see attached file for reference.

My question is that how to fix this problem so that the values of lamda1 = -lamda2, lamda3 = -lamda4 and lamda5 = -lamda6 on no matter the values of m and n are.

For instance, Iam looking for a method so that at any values of m and n, values of lamda's are always as follows:
lamda1 = -a;
lamda2 = a;
lamda3 = -b;
lamda4 = b;
lamda5 = -c;
lamda6 = c;

Thanks in advance for any response.
 

Attachments

  • LamdaPosition.nb
    9.7 KB · Views: 622
Physics news on Phys.org
  • #2
A quick fix might be replacing your

Code:
lamda[m_, n_] := Eigenvalues[D0[m, n]]

with

Code:
lamda[m_, n_] := SortBy[Eigenvalues[D0[m, n]], 
                            {Abs[# /. a -> 1.] &, Sign[# /. a -> 1.] &}]

which sorts the eigenvalues according to their absolute value and sign at the point a=1.
 
  • #3
Thank you.
 
  • #4
I just found out that the code does not work for lamda[7,3], lamda[59,79] etc.

The sign conventions are not consistent. Iam looking for a method in such a way that lamda1 = -a;
lamda2 = a;
lamda3 = -b;
lamda4 = b;
lamda5 = -c;
lamda6 = c;

where a, b and c can be complex numbers or real or combination of both.

Please help me to solve this matter.

many thanks for any feedback.
 
  • #5
You matrix is real, so the eigenvalues will come in complex conjugate pairs.
Breaking up the c.c. pairs like you want to do, is a little unusual.
If you wanted to sort by Abs[] then Arg[] then you'd get things in complex conjugate pairs. If you want in +- pairs, then you need to flip the quadrants around a little:

Code:
lambda[m_, n_] := 
 SortBy[Eigenvalues[D0[m, n]], {Abs[# /. a -> 1.] &, 
   If[0 < # < Pi, Mod[# + Pi/2, Pi], #] &@
       If[Pi/2 < # < Pi/2, -#, #] &@Arg[# /. a -> 1.] &}]

The above will return things sorted by absolute value. Then terms in the -Pi to -Pi/2 quadrant followed by its negative term. Then things in the Pi/2 to Pi quadrant followed by its negative.

The fact things always occur in +- pairs in your system, probably means that there's some symmetry/structure you should be exploiting. If you find it, then you can just calculate half the number of eigenvalues then add in their negatives...

The other way to maybe sort you list is just by the Real part. Then it will be
{-a,-b,-c,c,b,a} and you can fold it back in on itself:

Code:
lambda[m_, n_] := 
 SortBy[Eigenvalues[D0[m, n]], {Re[# /. a -> 1.] &, 
    Im[# /. a -> 1.] &}][[{1, 6, 2, 5, 3, 4}]]

it's not the same order as above, but it does fit your criteria.
 
  • #6
you are genius... The last code that Iam looking for and it really works.

thanks a lot and I really appreciate it. Have a nice day..
 

1. How do I calculate the eigenvalues of a matrix in Mathematica?

To calculate the eigenvalues of a matrix in Mathematica, you can use the built-in function Eigenvalues[matrix]. This will return a list of the eigenvalues of the given matrix.

2. How can I ensure that the eigenvalues are consistently ordered in Mathematica?

In order to consistently order the eigenvalues in Mathematica, you can use the option Eigensystem[matrix, Sort]. This will sort the eigenvalues in ascending order.

3. Can I customize the ordering of eigenvalues in Mathematica?

Yes, you can customize the ordering of eigenvalues in Mathematica by using the Eigensystem[matrix, order] function, where order can be set to Ascending, Descending, or a custom ordering function.

4. How do I calculate the eigenvalues of a large matrix efficiently in Mathematica?

For large matrices, it is recommended to use the Eigensystem[matrix, -1] function in Mathematica, which uses an iterative method to calculate the eigenvalues without computing the entire matrix.

5. Can I find the eigenvectors associated with the eigenvalues in Mathematica?

Yes, the Eigensystem[matrix] function in Mathematica also returns the eigenvectors associated with the eigenvalues. It will return a list of two elements, where the first element contains the eigenvalues and the second element contains the corresponding eigenvectors.

Similar threads

Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Quantum Physics
Replies
2
Views
971
  • Introductory Physics Homework Help
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Math Proof Training and Practice
Replies
25
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
52
Views
11K
Back
Top