# MATLAB: QR decomposition with the output of a permutation vector

qr decomposition

It is noted that the Matlab syntax for qr decomposition (https://www.mathworks.com/help/symbolic/qr.html#d120e152496):
[Q,R,P] = qr(A) returns an upper triangular matrix R, a unitary matrix Q, and a permutation matrix P, such that A*P = Q*R. If all elements of A can be approximated by the floating-point numbers, then this syntax chooses the column permutation P so that abs(diag(R)) is decreasing.
For example: A = [12 -51 4; 6 167 -68; -4 24 -41]
Then, [Q,R, P] = qr(A)
``Q =   -0.2894   -0.4682   -0.8349    0.9475   -0.0160   -0.3194    0.1362   -0.8835    0.4483R =  176.2555  -71.1694    1.6680         0   35.4389   -2.1809         0         0  -13.7281P =     2     3     1``
What's the physcial meaning of the fact that the diagnoal elements of R matrix are decreasing in magnitude? Without the output P, the resulting Q and R occurs in a different order in its column vectors.
I am not clear of how these different demposition behaviors occur. What's the specific algorithm Matlab is using for qr? Householder reflections (https://blogs.mathworks.com/cleve/2016/10/03/householder-reflections-and-the-qr-decomposition/)? Any relevant resources are welcome.

``>> A = [0 3 -2 1; 0 -6 4 -2; 0 2 -3 -1; 0 1 1 2];>> [Q, R] = qr(A); RR =         0    3.0000   -2.0000    1.0000         0    6.4031   -4.5290    1.8741         0         0    2.3426    2.3426         0         0         0   -0.0000>> [Q, R, P] = qr(A); RR =   -7.0711   -2.1213    4.9497         0         0    2.3452    2.3452         0         0         0   -0.0000         0         0         0         0         0         ``