function [Theta]=DualEst(lambda,W,G,M,K,Pbar)
maxP = zeros(K,M);
P = W/(log(2)*lambda)-1./G;
P(find(P<0))=0;
Pest = 0.001*log(1+exp(1000*(W/(log(2)*lambda)-1./G)));
C = W.*log2(1+P.*G)-lambda*P;
[maxC maxCidx] = max(C');
% maxP((maxCidx-1)*K+[1:K]) = P((maxCidx-1)*K+[1:K]);
% Theta = lambda*Pbar + sum(maxC);
Theta = lambda*Pbar+sum(1/1000*log(sum((((1+1000*G.*W/(lambda*log(2))).^(W/log(2)))./(1+exp(1000*(W/log(2)-lambda./G)))).')));

