# RandomStateVector

 Other toolboxes required RandomStateVector Generates a random pure state vector none RandomDensityMatrixRandomProbabilitiesRandomSuperoperatorRandomUnitary Random things

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 should be a 1-by-2 vector containing the desired local dimensions.
• RE (optional, default 0): A flag (either 0 or 1) indicating that V should only have real entries (RE = 1) or that it is allowed to have complex entries (RE = 0).
• K (optional, default 0): If equal to 0 then V will be generated without considering its Schmidt rank. If K > 0 then a random pure state with Schmidt rank ≤ K will be generated (and with probability 1, its Schmidt rank will equal K). Note that when K = 1 the states on the two subsystems are generated uniformly and independently according to Haar measure on those subsystems. When K = DIM, the usual Haar measure on the total space is used. When 1 < K < DIM, 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}$).

## Examples

### A random qubit

To generate a random qubit, use the following code:

>> RandomStateVector(2)

ans =

-0.1025 - 0.5498i
-0.5518 + 0.6186i

If you want it to only have real entries, set RE = 1:

>> RandomStateVector(2,1)

ans =

-0.4487
0.8937

### 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:

>> v = RandomStateVector(3,0,1)

v =

0.0400 - 0.3648i
0.1169 - 0.0666i
0.0465 + 0.0016i
-0.1910 + 0.0524i
-0.0566 - 0.0455i
-0.0084 - 0.0236i
-0.4407 + 0.7079i
-0.3050 + 0.0214i
-0.0936 - 0.0489i

>> SchmidtRank(v)

ans =

1

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:

>> v = RandomStateVector([3,4],0,2)

v =

-0.2374 + 0.1984i
0.1643 + 0.0299i
-0.0499 + 0.0376i
-0.0689 - 0.0005i
0.7740 - 0.0448i
-0.1290 - 0.2224i
-0.0514 - 0.1565i
0.2195 + 0.2478i
-0.1636 + 0.1276i
0.0581 + 0.0608i
0.0482 - 0.0178i
-0.1050 + 0.0014i

>> SchmidtRank(v,[3,4])

ans =

2