function C = WeightedPartialCSIConst(Gamma,w,sigma2w,sigma2e,Pbar) 
[K,M] = size(Gamma);
for k = 1 : K
  for m = 1 : M
      gbar = sigma2e(k)/sigma2w;
      ghat = G(k,m);
      Cmat(k,m) = quad(@(x) myintegrand(x,P(k,m),ghat,gbar),0,ghat+gbar+10*sqrt(gbar^2+2*ghat*gbar));
      end;      
  end;
end;
Piter = mean(mean(mean(I)));
[maxC maxCidx] = max(C,[],2);
Theta = lambda*Pbar + mean(sum(maxC));
if computePC
  linidx = sub2ind([K,M],(1:K)',maxCidx);
  maxP(linidx) = P(linidx);
  ptot = sum(sum(maxP));
  maxP = maxP*Pbar/ptot;
  for k = 1 : K
    if maxP(k,maxCidx(k)) > 0
      gbar = sigma2e(k)/sigma2w;
      ghat = G(k,maxCidx(k));
      maxCmat(k,maxCidx(k)) = quad(@(x) myintegrand(x,maxP(k,maxCidx(k)),ghat,gbar),0,ghat+gbar+10*sqrt(gbar^2+2*ghat*gbar));
    end
  end  
else
  maxP = 0;
  maxCmat = 0;
end

end
function y = myintegrand(x,p,ghat,gbar)
y = log2(1+p*x)/gbar.*exp(-(ghat+x)/gbar).*besseli(0,2/gbar*sqrt(ghat*x));
y(isinf(y)|isnan(y))=0;
end

Cmat3 = log2(1+Gamma);
[WCtmp3,WCtmp3idx] = max(repmat(w,size(Gamma,1),1).*Cmat3,[],2);
linidx = sub2ind(size(Gamma),(1:size(Gamma,1))',WCtmp3idx);
Ctmp = zeros(size(Gamma));
Ctmp(linidx) = Cmat3(linidx);
C = sum(Ctmp);