Skip to content

rands

Random symmetric matrix.

r = rands(n)
r = rands(n, classname)

Returns an n×n symmetric matrix whose upper triangle is filled with uniform [0, 1] samples and whose lower triangle mirrors it. Useful as test data for symmetric-matrix algorithms (eigendecomposition, Cholesky, etc.).

rands(4) % 4×4 symmetric uniform matrix
isequal(rands(5), rands(5)') % 1 (always symmetric)
  • rand — Uniformly distributed random numbers in [0, 1].
  • randh — Random Hermitian (complex symmetric) matrix.