0

Let me preface that I am an absolute beginner with Matlab. I am trying to perform $PA=LU$ factorization on a matrix, however I am having difficulty with the permutation matrix. When I execute $[L,U,P]=lu(A)$, I want to be able to represent the permutation matrix as a one-dimensional array of integers recording which row interchanges have been made.

For example, if $P=[0 1 0 ; 1 0 0 ; 0 0 1]$, then I am looking to find how I can achieve an output of $p= [2 1 3]$.

I figure that there was an easy way to execute this result. I simply do not have the experience to figure it out on my own. Thank you.

Amzoti
  • 56,629
user42864
  • 207

1 Answers1

2

Compute $P \cdot \left(\begin{array} &1 \\ 2 \\ 3 \\ \end{array} \right)$, and then transpose to get it in rowvector shape.

  • I see what you did there if the permutation is a 3x3 matrix. But what if a matrix is NxN in size? – user42864 Feb 11 '13 at 16:14
  • The same basic principle holds except you should multiply it with the vector $\left( \begin{array}{c} 1 \ 2 \ \dots \ N \end{array} \right)$. – Patrick Hafkenscheid Feb 13 '13 at 10:25
  • How do you do the opposite in Matlab (convert a permutation vector into a matrix)? See my question at http://math.stackexchange.com/questions/379809/is-there-a-name-for-this-function-parity-of-a-finite-sequence . – Stefan Smith May 03 '13 at 02:45