-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathEntropy.m
30 lines (26 loc) · 827 Bytes
/
Entropy.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
30
%% ENTROPY Computes the von Neumann entropy of a density matrix
% This function has one required argument:
% RHO: a density matrix
%
% ENT = Entropy(RHO) is the (base 2) von Neumann entropy of RHO.
%
% This function has one optional input argument:
% BASE (default 2)
%
% ENT = Entropy(RHO,BASE) is the von Neumann entropy of RHO, computed
% with logarithms in the base specified by BASE.
%
% URL: http://www.qetlab.com/Entropy
% requires: nothing
% author: Nathaniel Johnston (nathaniel@njohnston.ca)
% version: 0.50
% last updated: September 9, 2014
function ent = Entropy(rho,varargin)
% set optional argument defaults: base=2
[base] = opt_args({ 2 },varargin{:});
lam = eig(rho);
if(base == 2)
ent = -sum(real(lam.*log2(lam)));
else
ent = -sum(real(lam.*log(lam)))/log(base);
end