-
Notifications
You must be signed in to change notification settings - Fork 29
/
Concurrence.m
29 lines (23 loc) · 954 Bytes
/
Concurrence.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%% CONCURRENCE Computes the concurrence of a 2-qubit state
% This function has one required argument:
% RHO: a pure state vector or a density matrix
%
% C = Concurrence(RHO) is the concurrence of the two-qubit state RHO.
%
% URL: http://www.qetlab.com/Concurrence
% requires: Pauli.m, pure_to_mixed.m
% author: Nathaniel Johnston ([email protected])
% package: QETLAB
% last updated: February 19, 2016
function c = Concurrence(rho)
rho = pure_to_mixed(rho); % Let the user input either a pure state vector or a density matrix.
[m,n] = size(rho);
if m ~= 4 || n ~= 4
error('Concurrence:InvalidDim','The concurrence is only defined for two-qubit states (i.e., 4-by-4 density matrices).');
end
% Construct the spin-flipped matrix \tilde{\rho}.
Y = Pauli('Y');
rhotilde = kron(Y,Y)*conj(rho)*kron(Y,Y);
% Compute the concurrence.
lam = sort(abs(sqrt(eig(rho*rhotilde))),'descend');
c = max(lam(1)-lam(2)-lam(3)-lam(4),0);