# sorting eigenvectors of a final combined matrix

I have two matrices m1 and m2 as below:

m1 = {{1, 2, 4, 6}, {2, 0, 3, 4}, {1, -1, -4, 4}, {0, 2, -2, -1}};
m2 = {{0, -2, 2, 1}, {1, 0, 2, 1}, {1, -1, -2, 1}, {1, 3, -2, -1}};


these matrices are multiplied by varying real numbers n1 and n2 (n1*m1 and n2*m2). Although I can obtain sorted Eigenvectors of n1*m1 with this command:

storeigenm1 = {};
Block[{nx = 3, intervals = 0.5},
storeigenm1 =
Flatten[Last /@
SortBy[Transpose@MapAt[Orthogonalize, Eigensystem[#*m1], 2],
First] & /@ Range[0, nx, intervals], 1]];


When I use storeigenm1//MatrixForm I can see a 36*1 matrix, because at any step of n1 (which is varied in the code from nx=0 to 3 by 0.5 intervals that equals to 9 stages and at any stage there are 4 eigenvectors thus the final results has 36 row). Sorting of Eigenvectors done based on Eigenvalues amounts.

{related to lowest Eigenvalue.......................... Eigenvector of 0*m1
second ..................... Eigenvector of 0*m1
third.......................... Eigenvector of 0*m1
fourth........................... Eigenvector of 0*m1

first............................Eigenvectot of 0.5*m1
second............................Eigenvectot of 0.5*m1
third...........................Eigenvectot of 0.5*m1
fourth............................Eigenvectot of 0.5*m1
.
.
.
.

..................................Eigenvectot of 3*m1}


But the main goal and main question is related to sort Eigenvectors of a combination of m1 and m2 (which multiplied by n1 and n2) which should be as below

{first........................... Eigenvector of 0*m1 + 0*m2
second........................... Eigenvector of 0*m1 + 0*m2
third........................... Eigenvector of 0*m1 + 0*m2
fourth........................... Eigenvector of 0*m1 + 0*m2

first...........................Eigenvectot of 0.5*m1 + 0*m2
second............................Eigenvectot of 0.5*m1 + 0*m2
third..........................Eigenvectot of 0.5*m1 + 0*m2
fourth...........................Eigenvectot of 0.5*m1 + 0*m2
and so on (same as below in which I don't bring all of element and just I    partly write of them)
..................................Eigenvectot of 1*m1 + 0*m2

....
................................ Eigenvector of 0*m1 + 2.5*m2
.................................Eigenvectot of 0.5*m1 + 2.5*m2
..................................Eigenvectot of 1*m1 + 2.5*m2

....
..................................Eigenvectot of 2.5*m1 + 4*m2
..................................Eigenvectot of 3*m1 + 4*m2}


m2 multiplied by 4 since the final value of n2 is different of n1.

I would be so glad to know how I change the main command for this goal?

• It's hard to understand what you are doing with your code, with the composition of Flatten[Last /@ SortBy[Transpose@MapAt[Orthogonalize..... . To start with, what is the benefit of applying Orthogonalize to the eigenvectors? Aren't the vectors that come out of Eigensystem already an orthonormal basis? Commented Jan 11, 2016 at 9:50
• No they need to be normalized. Commented Jan 11, 2016 at 9:59
• I am not insistent on the mentioned code, each code that solves the problem can come to me. I will be so glad. Commented Jan 11, 2016 at 10:01
• Okay, but the eigenvectors of 0.5 m1 are normalized: Norm /@ Eigenvectors[0.5 m1] returns {1., 1., 1., 1.} Commented Jan 11, 2016 at 10:02
• Another point is that m1 and n1*m1 should have exactly the same eigenvectors, so why make the table in the first place? Commented Jan 11, 2016 at 10:14

To get the exact same output as your code, where you use Orthogonalize on the eigenvectors, use this

storeigenm1 = Join @@ Table[
Sort@Orthogonalize@Eigenvectors[n m1]
, {n, 0, 3, .5}];


This is easier to understand, as it doesn't have the unneeded Transpose, SortBy, First, Last, or MapAt.

But really, Eigenvectors by default returns normalized, orthogonal vectors when the input matrix is numerical (i.e. not composed of integers or other exact numbers like e and π). And there you have the benefit that they are already sorted in order of their eigenvalues (from largest to smallest). Your output is sorted in order of the first element of the eigenvector, rather than by the eigenvalue which seems a better sorting criterion. Below I reverse the sorting, so that they come in increasing order of the eigenvalue (lowest first) which always seemed a better way to me.

So just do this,

storeigenm1 = Join @@ Table[
Reverse @ Eigenvectors[N @ n m1]
, {n, 0.0, 3, .5}];


and skip the Orthogonalize altogether. To do the list you ask for, just add another iterator to the Table and then use Flatten[ ,2] on the result.

storeigenm1m2 = Flatten[
Table[
Reverse@Eigenvectors[N@(1 m1 + n2 m2)]
, {n1, 0, 3, .5}
, {n2, 0, 4, .5}]
, 2];


Of course you can use the Sort@Orthogonalize instead here.

• Besides so much thanks for your trying I will be happy to let me understand your steps and apply them. Commented Jan 11, 2016 at 10:42
• Please check the length of output: it has 252 rows, I expected it has (6*8*4=192) rows!!!!! and for example please check: storeigenm1 = Flatten[Table[Reverse@Eigenvectors[N@(n1 m1)], {n1, 0, 3, .5}], 1]; just for m1 and for each 0, 0.5, 1, 1.5, 2, 2.5, 3 there was 4 eigen vector all must be 24 but it has 28!!!!!!!!!!! Commented Jan 11, 2016 at 15:08
• @Bstates, you have two loops, one going from 0 to 3 in steps of 0.5 (seven steps total), and another loop from 0 to 4 in steps of 0.5 (nine steps total). So that is 63 sets of four eigenvectors. It has the dimensions I would expect: 252 = 7*9*4. Commented Jan 11, 2016 at 15:12
• you are right I did not count zero!!! Commented Jan 11, 2016 at 15:49