Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to apply Eigenvalues[] to a list of matrices as in the following

foo[x_,y_]=x+y;

({{foo[#1, #2], foo[#1, #1]},
 {foo[#1, #1], foo[#1, #2]}}) & @@@ {{1, 2}, {1, 2}}

--> {{{3, 2}, {2, 3}}, {{3, 2}, {2, 3}}}

Eigenvalues @@@ %

However, I get the error-message "Eigenvalues::matsq: Argument 3 at position 1 is not a non-empty square matrix". What is the problem?

share|improve this question
1  
You need to use Map, not Apply. Additional braces are not necessary. –  Szabolcs Mar 25 at 14:17

2 Answers 2

up vote 4 down vote accepted

Padding additional brackets is not the right way to do it. You should use the right function for the task, which is Map:

matrices = {{{3, 2}, {2, 3}}, {{3, 2}, {2, 3}}};
Eigenvalues /@ matrices

If you're insistent on using Apply (why?), then the following ways work:

Eigenvalues[{##}] & @@@ matrices
Eigenvalues @@@ List /@ matrices
share|improve this answer
    
EigenValues @@@ {matrices} does not do the same thing as the others. –  RunnyKine Mar 25 at 14:47
    
@RunnyKine Thanks for catching that! Fixed now. –  rm -rf Mar 25 at 15:05
    
Sure thing. Thanks for fixing it. +1 –  RunnyKine Mar 25 at 15:12

I got it: one has to put additional brackets around the first pure function:

{({{foo[#1, #2], foo[#1, #1]},
 {foo[#1, #1], foo[#1, #2]}})} & @@@ {{1, 2}, {1, 2}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.