I am reading this paper, where at page $68$, section 3.3 (numerical examples for the Drazin inverse), the randomly generated matrix with specified rank and with the property that each eigenvalue is real and has single multiplicity is constructed. It is mentioned that such matrices can be constructed by taking $A = PDP^{*}$, where $P$ is random orthogonal matrix, $D =diag(\lambda_1, \lambda_2, \ldots \lambda_r,0,\ldots 0) $. Eigenvalues $\lambda_1, \lambda_2, \ldots \lambda_r,0$ are arbitrary randomly generated positive real numbers. $P^{*}$ denote the conjugate transpose of the matrix $P$.
I need help to make matlab code for constructing matrices with such properties.
Thank you very much for your time.
Here's one way to construct $A$ using Matlab:
You can check that the rank of $A$ is $r$ and that the eigenvalues of $A$ are the values stored in the variable lambda.