% Testing approximation to Imperfect CSI power allocation function
g0 = .1;
ghatvec = linspace(-10,10,20);
gbarvec = 10.^((-10:5:5)/10);
p = zeros(length(gbarvec),length(ghatvec));
papp = p;
pwf = p;
for i = 1:length(gbarvec)
  gbar = gbarvec(i);
  for j = 1:length(ghatvec)
    i,j
    ghat = 10^(ghatvec(j)/10);
    if ghat+gbar<g0
      p(i,j)=0;
    else
      p(i,j) = fzero(@(x) PowerImperfectCSI(x,ghat,1,gbar,g0,log(2)),[0,1/g0]);
    end;
    pwf(i,j) = max(1/g0-1/ghat,0);
    papp(i,j) = approxPAimpCSI(ghat,gbar,g0,p(i,j));
  end
end
plot(ghatvec,p,'-',ghatvec,papp,'x'ghatvec,pwf,'--')
xlabel('\gamma (dB)')
ylabel('power')