gusucode.com > qit_matlab_0.10.0工具箱源码程序 > qit/@state/prob.m

    function p = prob(s)
% PROB  Measurement probabilities of the state in the computational basis.
%  p = prob(s)
%
%  Vector p holds the probabilities of finding a system
%  in the state s in all the different states of the computational basis.

% Ville Bergholm 2009


if is_ket(s)
  % state vector
  p = abs(s.data).^2;
else
  % state operator
  p = real(diag(s.data));
end