The documentation about LinearAlgebra has a section on Constructing Matrices, but the examples of random matrices using RandomReal
don't offer an obvios way to impose symmetry or rank.
There is a similar question (77441) asking for a matrix with a particular rank, but doesn't address the symmetry constraint.
Is there any way to create a $n \times n$ random symmetric matrix with a specified MatrixRank
$r$?
i.e. A $6 \times 6$ random symmetric matrix with rank $3$.
symm[n_] := Module[{mm = RandomReal[10, {n, n}]}, (mm + Transpose[mm])/2]
which creates a symmetric random matrix. Then I remembered the strongly related to the OPanswer
which constructs a random matrix of specific rank. Combining the above should do the trick, but I am stupid and I have not managed that yet $\endgroup$RandomMatrix[rank_, m_] := Sum[TensorProduct@symm[m], {i, rank}]
fails and likewise forRandomMatrix[rank_, m_] := Sum[TensorProduct /@ symm[m], {i, rank}]
as the rank becomes 6 instead of 3 $\endgroup$MatrixRank
. Next time you should do that or more, not less. $\endgroup$