function [p,x]=array(P,X)
P=[P;X];
[l,n]=size(P);
for i=1:n
max=P(1,i);
maxN=i;
MAX=P(:,i);
for j=i:n
if (max<P(1,j))
MAX=P(:,j);
max=P(1,j);
maxN=j;
end
end
if (maxN>1)
if (i<n)
for k=(maxN-1):-1:i
P(:, k+1)=P(:,k);
end
end
end
P(:,i)=MAX;
end
p=P(1,:);
x=P(2,:);
function [W,L,q]=shannon(p)
if (length(find(p<=0))
~
=0)
error('Not a prob.vector,negative component');
end
if (abs(sum(p)-1)>10e-10)
error('Not a prob.vector,component do not add up to 1')
end
n=length(p);
x=1:n;
[p,x]=array(p,x);
l=ceil(-log2(p));
P(1)=0;
n=length(p);
for i=2:n
P(i)=P(i-1)+p(i-1);
end
for i=1:n