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
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개)

질문:

El
2013년 3월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by