Purity
From QETLAB
Purity | |
Computes the purity of a quantum state | |
Other toolboxes required | none |
---|---|
Function category | Miscellaneous |
Purity is a function that computes the purity of a quantum state $\rho$ (i.e., it computes the quantity ${\rm Tr}(\rho^2)$).
Contents
Syntax
- GAMMA = Purity(RHO)
Argument descriptions
- RHO: A density matrix to have its purity computed.
Examples
Purity of pure states
Pure states have purity equal to 1, as illustrated by the following code:
>> phi = RandomStateVector(3); >> Purity(phi*phi') ans = 1.0000 >> Purity(RandomDensityMatrix(3,0,1)) ans = 1.0000
Purity of mixed states
If $\rho \in M_d$ is mixed then its purity is strictly less than 1. Its purity attains its minimum value of $1/d$ if and only if $\rho$ is the maximally-mixed state (i.e., the scaled identity operator).
Source code
Click on "expand" to the right to view the MATLAB source code for this function.
%% PURITY Computes the purity of a quantum state
% This function has one required argument:
% RHO: a density matrix
%
% GAMMA = Purity(RHO) is the purity of the quantum state RHO (i.e., GAMMA
% is the quantity trace(RHO^2)).
%
% URL: http://www.qetlab.com/Purity
% requires: nothing
% author: Nathaniel Johnston (nathaniel@njohnston.ca)
% package: QETLAB
% last updated: October 15, 2014
function gamma = Purity(rho)
gamma = real(trace(rho^2)); % "real" gets rid of close-to-0 imaginary part