Pure to mixed
From QETLAB
pure_to_mixed | |
Converts a state vector or density matrix representation of a state to a density matrix | |
Other toolboxes required | none |
---|---|
Function category | Helper functions |
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function. |
pure_to_mixed is a function that convert's a state's current representation (either as a pure state vector or as a density matrix) into a density matrix.
Syntax
- RHO = pure_to_mixed(PHI)
Argument descriptions
- PHI: A density matrix or a pure state vector.
Examples
The following code shows that if v is a pure state vector then pure_to_mixed(v) == v*v', yet if rho is a density matrix then pure_to_mixed(rho) == rho.
>> v = RandomStateVector(2) v = 0.6732 - 0.5736i 0.3190 + 0.3407i >> pure_to_mixed(v) ans = 0.7822 0.0193 - 0.4123i 0.0193 + 0.4123i 0.2178 >> pure_to_mixed(v*v') ans = 0.7822 0.0193 - 0.4123i 0.0193 + 0.4123i 0.2178 >> v*v' ans = 0.7822 0.0193 - 0.4123i 0.0193 + 0.4123i 0.2178
Source code
Click on "expand" to the right to view the MATLAB source code for this function.
%% pure_to_mixed Converts a state vector or density matrix representation of a state to a density matrix
% This function has one required argument:
% PHI: a density matrix or a pure state vector
%
% RHO = pure_to_mixed(PHI) is a density matrix representation of PHI,
% regardless of whether PHI is itself already a density matrix, or if it
% is a pure state vector.
%
% URL: http://www.qetlab.com/pure_to_mixed
% requires: nothing
% author: Nathaniel Johnston (nathaniel@njohnston.ca)
% package: QETLAB
% last updated: January 12, 2016
function rho = pure_to_mixed(phi)
% Compute the size of phi. If it's already a mixed state, leave it alone.
% If it's a vector (pure state), make it into a density matrix.
[m,n] = size(phi);
if(min(m,n) == 1) % it's a pure state vector
phi = phi(:);
rho = phi*phi';
elseif(m == n) % it's a density matrix
rho = phi;
else % it's neither
error('pure_to_mixed:InvalidDimensions','PHI must be either a vector or a square matrix.');
end