Function Repository Resource:

# RandomMatrix

Get a pseudorandom matrix of a given kind, type and size

Contributed by: Dennis M Schneider
 ResourceFunction["RandomMatrix"][type,range,n] returns an n×n matrix with entries Random[type,range]. ResourceFunction["RandomMatrix"][type,range,{m,n}] returns an m×n matrix with entries Random[type,range]. ResourceFunction["RandomMatrix"][Complex,range,n]] returns an n×n matrix with entries RandomComplex[range,n]. ResourceFunction["RandomMatrix"][Complex,range,{m,n}]] returns an m×n matrix with entries RandomComplex[range,{m,n}]. ResourceFunction["RandomMatrix"][GaussianInteger,range,n] returns an n×n matrix with entries Random[Integer, range]+IRandom[Integer, range]. ResourceFunction["RandomMatrix"][GaussianInteger,range,{m,n}] returns an m×n matrix with entries Random[Integer, range]+IRandom[Integer, range]. ResourceFunction["RandomMatrix"][GaussianRational,range,n] returns an n×n matrix with entries RandomRational[range]+IRandomRational[range]. ResourceFunction["RandomMatrix"][GaussianRational,range,{m,n}] returns an m×n matrix with entries RandomRational[range]+IRandomRational[range]. ResourceFunction["RandomMatrix"][kind,type,range,n] returns an n×n kind matrix with entries generated by Random[type,range].

## Details and Options

The type can be Integer, Rational, Real, Complex, "GaussianInteger" or "GaussianRational".
The kinds of square matrices allowed are: "Hermitian", "Idempotent", "Involution", "Orthogonal", "Reflection", "SkewHermitian", "SkewSymmetric", "Symmetric", "IdempotentSymmetric", "Reflection", "Triangular", "Unimodular", and "Unitary".
For matrices of kind “Idempotent” or “IdempotentSymmetric”, setting the option “Rank” k will choose a matrix of that kind having rank k.
The type and range specificaions only specify the type and range of the data used to generate the random matrix, not necessairly the type and range of the resulting matrix.

## Examples

### Basic Examples (6)

A random 2×3 real matrix generated by real numbers between 0 and 1:

 In[1]:=
 Out[1]=

A random 4×5 integer matrix of rank 3 generated by integers between -5 and 10:

 In[2]:=
 Out[3]=

A random 4×4 rational matrix generated by integers between -5 and 10:

 In[4]:=
 Out[5]=

A random 4×5 Gaussian integer matrix of rank 3 generated by Gaussian integers between -5 and 10:

 In[6]:=
 Out[7]=

A random 4×5 matrix of rank 3 whose entries are Gaussian rationals generated by integers between -5 and 10:

 In[8]:=
 Out[9]=

A random 4×4 matrix of rank 2 whose entries are complex numbers generated by RandomComplex[{-5+2I,10-3I}]:

 In[10]:=
 Out[11]=

### Scope (26)

Examples of special kinds of square matrices:

#### Triangular (1)

A random 4×4 upper triangular matrix with integer entries:

 In[12]:=
 Out[12]=

#### Symmetric (2)

A random 5×5 symmetric matrix with integer entries:

 In[13]:=
 Out[13]=

Check:

 In[14]:=
 Out[14]=

#### AntisymmetricMatrixQ or Skew-Symmetric (2)

A random 3×3 skew-symmetric matrix with integer entries:

 In[15]:=
 Out[15]=

Check:

 In[16]:=
 Out[16]=

A random 5×5 skew-symmetric matrix with rationals entries:

 In[17]:=
 Out[17]=

Check:

 In[18]:=
 Out[18]=

#### Hermitian (2)

A random 4×4 Hermitian matrix with Gaussian integer entries:

 In[19]:=
 Out[19]=

Check:

 In[20]:=
 Out[20]=

#### Skew-Hermitian (2)

A random 4×4 skew-Hermitian matrix with Gaussian integer entries:

 In[21]:=
 Out[21]=

Check:

 In[22]:=
 Out[22]=

A random 4×4 skew-Hermitian matrix with Gaussian rational entries:

 In[23]:=
 Out[23]=

Check:

 In[24]:=
 Out[24]=

#### Involution  (2)

A random 4×4 involution matrix generated by vectors with integer entries and given range specifications:

 In[25]:=
 Out[25]=

Check:

 In[26]:=
 Out[26]=

#### Reflection (Symmetric Involution) (4)

A random 4×4 symmetric involution generated by vectors with integer and range specifications (geometrically these matrices represent orthogonal reflections in the column space of the matrix):

 In[27]:=
 Out[27]=

Check:

 In[28]:=
 Out[28]=

Verify that the column space is an invariant subspace:

 In[29]:=
 Out[29]=
 In[30]:=
 Out[30]=

Verify that vectors orthogonal to the column space are taken into their negatives:

 In[31]:=
 Out[31]=
 In[32]:=
 Out[32]=

#### Idempotent Symmetric (orthogonal projections) (2)

A random 4×4 Idempotent symmetric matrix generated by vectors with integer entries (geometrically these matrices represent orthogonal projections onto the column space of the matrix):

 In[33]:=
 Out[33]=

Check:

 In[34]:=
 Out[34]=

A random 6×6 idempotent symmetric matrix that represent the orthogonal projections onto a 4 dimensional subspace of the column space of the matrix):

 In[35]:=
 Out[35]=
 In[36]:=
 Out[36]=

#### Idempotent (2)

A random 5×5 idempotent matrix generated by vectors with integer entries:

 In[37]:=
 Out[37]=

Check:

 In[38]:=
 Out[38]=

A random 7×7 rank 5 idempotent matrix generated by vectors with integer entries:

 In[39]:=
 Out[39]=
 In[40]:=
 Out[40]=

#### Orthogonal (2)

A random 5×5 orthogonal matrix generated by vectors with integer entries:

 In[41]:=
 Out[41]=

Check:

 In[42]:=
 Out[42]=

#### Unimodular (Integer matrix with an integer inverse) (2)

A random 5×5 unimodular matrix with integer entries:

 In[43]:=
 Out[43]=

Check that the determinant is a unit and that the inverse has integer entries:

 In[44]:=
 Out[44]=

A random 5×5 unimodular matrix with Gaussian integer entries and a Gaussian integer inverse:

 In[45]:=
 Out[45]=

Check that the determinant is a unit and that the inverse has Gaussian integer entries:

 In[46]:=
 Out[46]=

#### Unitary (3)

A random 4×4 unitary matrix generated by vectors with Gaussian integer entries:

 In[47]:=
 Out[47]=

Check:

 In[48]:=
 Out[48]=

A random 4×4 unitary matrix with complex entries:

 In[49]:=
 Out[49]=

Check:

 In[50]:=
 Out[50]=

A random 4×4 unitary matrix with complex entries:

 In[51]:=
 Out[51]=

Check:

 In[52]:=
 Out[52]=

## Publisher

Dennis M Schneider

## Version History

• 2.0.0 – 21 August 2023
• 1.0.0 – 08 January 2021