|Produces a unitary operator that swaps two subsystems|
|Other toolboxes required||none|
|Related functions|| PermutationOperator|
|Function category||Permutations and symmetry of subsystems|
SwapOperator is a function that returns a unitary operator that swaps two subsystems. The unitary can be chosen to be full or sparse.
- S = SwapOperator(DIM)
- S = SwapOperator(DIM,SP)
- DIM: A specification of the dimensions of the subsystems that S will act on. DIM can be provided in one of two ways:
- If DIM is a scalar, then both subsystems are assumed to have dimension DIM.
- If the subsystems have unequal dimensions, DIM should be a 1-by-2 vector containing their dimensions.
- SP (optional, default 0): If set equal to 1, the swap operator is sparse. If equal to 0, the swap operator is full.
The standard swap operator
The following code produces the operator that swaps two qubits:
Click on "expand" to the right to view the MATLAB source code for this function.
%% SWAPOPERATOR Produces a unitary operator that swaps two subsystems
% This function has one required argument:
% DIM: the dimensions of the subsystems
% S = SwapOperator(DIM) is the unitary operator that swaps two copies of
% DIM-dimensional space. If the two subsystems are not of the same
% dimension, DIM should be a 1-by-2 vector containing the dimension of
% the subsystems.
% This function has one optional argument:
% SP (default 0)
% S = SwapOperator(DIM,SP) is as above, but the swap operator produced is
% sparse if SP = 1 and is full if SP = 0.
% URL: http://www.qetlab.com/SwapOperator
% requires: iden.m, opt_args.m, PermuteSystems.m, Swap.m
% author: Nathaniel Johnston (firstname.lastname@example.org)
% package: QETLAB
% last updated: November 12, 2014
function S = SwapOperator(dim,varargin)
% set optional argument defaults: sp=0
% allow the user to enter a single number for dim
dim = [dim,dim];
% swap the rows of Id appropriately