%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
%%%%% Base-4 Mean Rate and Capacity Rate Comparison--- Linear Time Scales:
%%%%%     tau_2n-1=tau_2n=tau_1(1+(alpha-1)(n-1))
%%%%%     Capacity Distribution: p_(2k-1)=p_(2k)=p^(1+(alpha-1)(k-1)); k=1 to n
%%%%%     
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all
p_A=[];
p_C=[];
CRate=[];
Rmd=[];
solup=[];
alphaa=1.5;
alphab=3;
alphainc=.1;
for alp=alphaa:alphainc:alphab
      p=.1:.00001:.9;
      n=2;   
      y=p+p.^alp-0.5;
      %y=2*p.^((alp-1)*n+1)-p.^(alp-1)-2*p+1;
      [rmd,ind]=min(abs(y));
      Rmd=[Rmd rmd];
      p_A=[p_A p(ind)];
      p_C=[p_C p(ind)^alp];
end
Rmd 
CRate=-log(p_A)/log(2);

% Mean Rate
a=alphaa:alphainc:alphab;
s=a-1;% 
n=4;
k=n/2;
base4=2*log(2*k)./log(2)./(2+s*(k-1));

% Human Rate
pat=.54+0.09*54/(54+38);
pcg=.38+0.09*38/(54+38);
human=-(pat*log(pat/2)+pcg*log(pcg/2))/log(2)./(pat+pcg*a);

figure(2)
hold off
alpha=alphaa:alphainc:alphab;
plot(alpha, CRate, 'k-', 'linewidth', 3)
hold on
plot(alpha,human,'b--', alpha, base4, 'r.', 'markersize', 10, 'linewidth',1)
legend('\tau_A K','\tau_A R(Human)','\tau_A R_c','fontsize',18)
plot([5/3 5/3],[0 2],'g--')
axis([alphaa alphab .9 1.7])
xlabel('\alpha = \tau_{3,4} / \tau_{1,2}','fontsize',18)
ylabel('Normalized Rates','fontsize',16)

