what is wrong? help me!
Show older comments
tic;
clear all;
clc;
%% Parameters
Pt = 1; % transmitter's power
sigma2 = 10^(-90*0.1); % antenna's noise -0 dB
N = 6; % 6 subcarriers
K = 3; % 3 users
M = 1; % 3 tranmist antennas
L = 4; % 4 channel delay taps
xi = 0.4; % harvesting efficiency
constraintE = 100e-6; % minimum required E
trials=700;
iter = 70;
inertia = rand; % w
coefficient = rand(1,2)*2; %c1,c2
numParticle = 200; %¨Ó¹Ç¹Í¹ØÀÒ¤
meansecrecy = 0;
penalty = 10000;
%% Fisrt round
h = (randn(M,L,K)+1i*randn(M,L,K))/sqrt(2*L); % uniform
H = fft(h,N,2);
rho=rand(numParticle,K);
Velocity=rand(numParticle,K);
pbest=rho;
for u=1:K
for m=1:numParticle
obtain(m,u)=(xi*rho(m,u)*Pt/N/M*sum(sum(abs(H(:,:,u)).^2))+ sigma2)+(constraintE - obtain(m,u))*penalty > 0.';
end
end
end
for indexStar = 1:K^N
%indexStar
kstar = dec2base(indexStar-1,K,N)-47;
for l=1:numParticle
if all(obtain(l,:))>=constraintE
for n=1:N
for k=1:K
r(k,n) = log2(1+Pt/N/M*(1-rho(l,k))/sigma2*abs(H(:,n,k))^2);
end
rTemp = r(:,n);
rTemp(kstar(n)) = 0;
new_secrecyrate(n) = max(r(kstar(n),n) - max(rTemp),0);
end
for u = 1:K
secrecyrateUser(:,u) = sum(new_secrecyrate(kstar==u));
end
meansecrecy(l)= mean(secrecyrateUser);
end
end
[dummy,bestrho] = max(meansecrecy);
gbest=pbest(bestrho,:);
r=rand(1,2);
Velocity=inertia*Velocity+coefficient(1)*r(1)*(pbest-rho)+coefficient(2)*r(2)*(repmat(gbest,numParticle,1)-rho);
rho=rho+Velocity;
end
toc
i want to intstall constain optimization and penalty help me please
3 Comments
Sargondjani
on 5 Feb 2019
try fmincon. or if you want to program it yourself, check the references therein.
Siraphop K.
on 5 Feb 2019
Walter Roberson
on 5 Feb 2019
that looks like a lb (lower bound) of eps(realmin)
Answers (0)
Categories
Find more on Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!