RandomStateVector

RandomStateVector is a function that generates a random pure state vector, uniformly distributed on the unit hypersphere (sometimes said to be uniformly distributed according to Haar measure).

Syntax

 * V = RandomStateVector(DIM)
 * V = RandomStateVector(DIM,RE)
 * V = RandomStateVector(DIM,RE,K)

Argument descriptions

 * DIM: The dimension of the Hilbert space in which V lives. If K > 0 (see optional arguments below) then DIM is the local dimension rather than the total dimension. If different local dimensions are desired, DIM</tt> should be a 1-by-2 vector containing the desired local dimensions.
 * RE</tt> (optional, default 0): A flag (either 0 or 1) indicating that V</tt> should only have real entries (RE = 1</tt>) or that it is allowed to have complex entries (RE = 0</tt>).
 * K</tt> (optional, default 0): If equal to 0 then V</tt> will be generated without considering its Schmidt rank. If K > 0</tt> then a random pure state with Schmidt rank &le; K</tt> will be generated (and with probability 1, its Schmidt rank will equal K</tt>). Note that when K = 1</tt> the states on the two subsystems are generated uniformly and independently according to Haar measure on those subsystems. When K = DIM</tt>, the usual Haar measure on the total space is used. When 1 < K < DIM</tt>, a natural measure that interpolates between these two extremes is used (more specifically, the direct sum of the left (similarly, right) Schmidt vectors is chosen according to Haar measure on $\mathbb{C}^K \otimes \mathbb{C}^{DIM}$).

A random qubit
To generate a random qubit, use the following code:

If you want it to only have real entries, set RE = 1</tt>:

Random states with fixed Schmidt rank
To generate a random product qutrit-qutrit state and verify that it is indeed a product state, use the following code:

You could create a random pure state with Schmidt rank 2 in $\mathbb{C}^3 \otimes \mathbb{C}^4$, and verify its Schmidt rank, using the following lines of code: