We may carry out the SVD ($A=U\Sigma V^T$) in such a way that the diagonal entries of $\Sigma$ are in descending order.
My question is, how to do this rearrangement? Can someone show me the details?
Another question: is the $A=U'\Sigma' V'^T$ still a valid SVD?
There are several explanations of SVD all over the place. Here is a link to some explanation in this forum.
Here is a construction that gets the ordering as you asked.
Suppose $A$ is an $m\times n$ matrix on $\mathbb{C}$. We use $A^*$ to denote the conjugate transpose of $A$ (this is an $n\times m$ matrix). In terms in operators on $L(\mathbb{C}^m,\mathbb{C}^n)$, $A^*$ is the operator that satisfies $$y^*Ax=\langle Ax,y\rangle = \langle x,A^*y\rangle=(A^*y)^*x$$
Some final remarks:
Matrices $Q$ and $P$ in the SVD decomposition of $A$, even when the main diagonal of $D$ is ordered decreasingly, are not unique (there is a choice in ordering eigenvectors corresponding to an eigenvalue of multiplicity > 1, another choice for completing an orthonormal basis to construct $P$, and multiplication of vectors by unitary scales will produce also different $Q$s and $P$s)
If a particular SVD decomposition $P,D,Q$ of $A$ is given, permutations on the main diagonal of $D$ ($\sigma_j$ and $\sigma_i$ are interchanged), results in interchanging the $i$-th and $j$-th rows of $Q$ and the $i$-th and $j$-th columns of $P$ in order to keep an identity of the form $A=(P')D'(Q')^*$.
There are efficient numerical algorithms to find the SVD decomposition already implemented in many libraries (BLAS, LAPACK, etc) that can be ported to Fortran, C, C++, etc. All of them, to my knowledge, produce an $m\times n$ diagonal $D$ matrix where the main diagonal is ordered decreasingly.
Edit: To address the comment if @Ian, define $P^{>}$ as the $m\times r$ matrix whose $j$-th column is $v_j=Au_j$ ($1\leq j\leq r$) and $P^0$ the $m\times (m-r)$ matrix whose $j$-th columns are given by the $m-r$ vectors $v_j$ used to complete a basis for $\mathbb{C}^m$. Then $P=[P^>|P^0]$. Let $D_{>}$ be the $r\times r$ diagonal matrix $\operatorname(diag)(\sigma_1,\ldots,\sigma_r)$. Let $Q^>$ be the $r\times n$ matrix whose $i$-th row ($1\leq i\leq r$) is $u^*_i$, and $Q^0$ the $(n-r)\times n$ matrix whose $i$-th row is $u_i$, $r< I$, corresponding to the zero eigenvalues of $A^*A$, that is $Q=\begin{pmatrix} Q^>\\-\\Q^0\end{pmatrix}$. Then \begin{align} A&=PDQ=\begin{pmatrix}P^>|P^0\end{pmatrix}\begin{pmatrix}D^>&|&0_{r\times(n-r)}\\ -&|&-\\ 0_{(m-r)\times r} &| &0_{(m-r)\times(n-r)}\end{pmatrix} \begin{pmatrix} Q^>\\-\\Q^0\end{pmatrix}\\ &=P^>D^>Q^> \end{align} Typical implementations of the svn algorithm has outputs $U=P^>_{m\times r}$, $\Sigma=D^>_{r\times r}$ and $V=Q^>_{r\times n}$.