Optimal power allocation using fmincon
显示 更早的评论
Hi all, I am Matlab begginer and I want to maximize the capacity with optimal power allocation, for different average power values, using fmincon but I can not understand what I am doing wrong. My code is:
function Cs_SingleAntenna_fullCSI
no_samples = 1e6; x0=0; A=[]; b=[]; Aeq =[]; beq=[]; lb=[];ub=[]; P_avdB = 0:5:35; P_av = zeros(1,length(P_avdB)); Sum = 0;
for i=1:length(P_avdB) P_av(i)=10^(P_avdB(i)/10); P_av1 = P_av(i); hm2 = exprnd(1,1,no_samples); hw2 = exprnd(1,1,no_samples); for m=1:no_samples if (hm2(m)>hw2(m)) hm = hm2(m); hw = hw2(m); myfun = @(P)fun(P,hm,hw,Sum); mycon = @(P)con1(P,P_av1); [P,fval]=fmincon(myfun,x0,A,b,Aeq,beq,lb,ub,mycon); end end end
figure; plot(P_avdB,fval); grid
function [f] = fun (P,hm,hw,Sum) no_samples = 1e6; Cs = log2(1+hm*P)-log2(1+hw*P); Sum = Sum + Cs; f = -Sum/no_samples; end
function [c,ceq] = con1(P,P_av1) c=[]; ceq=sum(P)/100000 - P_av1; end
Can somebody please help me?
Thank you in advance
1 个评论
Matt J
2013-3-10
Please apply the '{} Code' toolbar icon to your code to make it readable. Also, please explain why you think anything is wrong currently.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Choose a Solver 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!