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

1. Dec 15, 2011

### 7Deuce

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?

2. Dec 15, 2011

### AlephZero

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

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...