Is it possible to extract the diagonal elements of a matrix into a vector?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 9K views
7Deuce
Messages
1
Reaction score
0
Is it possible to extract the diagonal elements of a matrix into a vector??

Is it possible to extract the diagonal elements of a matrix into a vector USING ONLY MATRIX MULTIPLICATION? So no element by element multiplication, and no diag commands.

(This will eventually be implemented in MATLAB, but I am required to only use matrix multiplication, so no commands)

Is it even possible?

Thanks in advance.
 
Physics news on Phys.org


You can do it with a sequence of matrix multiplies and adds.

Think about how to get one diagonal element into a 1x1 matrix, and then how to "expand" the 1x1 matrix into the right place in a vector. Repeat and add...

Possibly you combine all those steps part of a bigger matrix multiply operation (I'm speculating here) If the given matrix is order N, you might need matrices with dimensions of N2 or even N3...