Code covered by the BSD License  

Highlights from
QUBIT4MATLAB V4.0

from QUBIT4MATLAB V4.0 by Geza Toth
MATLAB package for quantum information science and quantum mechanics.

rho_noisy=addnoise(rho,p)
% addnoise   Adds white noise to a density matrix.
%   addnoise(rho,p) computes the matrix 
%   rho'=(1-p)*rho+p*eye(M)/M where rho is an MxM matrix
%   If rho is a state vector then 
%   it is converted into a normalized density matrix.
%   If parameter d is omitted then it 
%   is taken to be 2 (qubits).

function rho_noisy=addnoise(rho,p)

% Convert state vector to density matrix if necessary
rho=ketbra2(rho);

% Obtain the size of the density matrix
[sx,sy]=size(rho);
rho_noisy=(1-p)*rho+p*eye(sx)/sx;

Contact us at files@mathworks.com