程序.rar

  • 对酒当歌0901
    了解作者
  • matlab
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2021-03-23 20:50
    上传日期
平时看的论文的仿真复现,其主要内容是关于MEC及Lyapunov优化
程序.rar
  • 程序
  • suiji9_21.m
    6.5KB
内容介绍
clear all;clc; syms c tau=10^(-3); W=10^7; N0 = 10^(-174/10 - 3 ); g0 = 10^(-40/10 ); d0 = 1; d = 150; theta = 4; w = 1; wn = 0; k = 10^(-27); fimax = 10^(9); pimax = 0.5; Li = 737.5; fcmax = 2.5*10^9; N = 5; M = 8; Z = linspace(0,4*10^9,10); for m = 1:10 V = Z(m); Q = zeros(1,N,100);T = zeros(1,N,100); for timeIndex = 1:100 a = rand(1,N).*8000; for i = 1:N A(1,i,timeIndex) = a(i); end b = exprnd(1,1,N); %随机产生指数分布的1*N的矩阵 for i = 1:N gama(1,i,timeIndex) = b(1,i); end for i = 1:N GAMA(1,i,timeIndex) = gama(1,i,timeIndex)*g0*(d0/d)^(theta); end for i = 1:N fi(1,i,timeIndex) = min(fimax,sqrt(Q(1,i,timeIndex)*tau/(3*k*V*Li*w))); end for i = 1:N Dl(1,i,timeIndex) = tau*fi(1,i,timeIndex)/Li; end for i = 1:N pl(1,i,timeIndex) = k*fi(1,i,timeIndex)^3; end % for i = 1:N % alpha(1,i,timeIndex) = 1/N; % end % % for i = 1:N % if Q(1,i,timeIndex) > T(1,i,timeIndex) % ptx(1,i,timeIndex) = min(alpha(1,i,timeIndex)*W*max((Q(1,i,timeIndex) - T(1,i,timeIndex))*tau/(0.693*V*w) - N0/GAMA(1,i,timeIndex),0),pimax); % else % ptx(1,i,timeIndex) = 0; % end % end gains = 1;times=1;eps = 10^(-4); while (gains > 0.0000001) if times == 1 for i = 1:N if Q(1,i,timeIndex) <= T(1,i,timeIndex) alpha2(1,i,times) = 0; else alpha2(1,i,times) = eps; end end end nc= 0 ; for i = 1:N if Q(1,i,timeIndex) <= T(1,i,timeIndex) alpha1(1,i,times) = eps; nc = nc + 1; else alpha1(1,i,times) = 0; end end for i = 1:N alpha(1,i,times) = alpha1(1,i,times) + alpha2(1,i,times); end for i = 1:N if Q(1,i,timeIndex) <= T(1,i,timeIndex) Ptx(1,i,times) = 0; else Ptx(1,i,times)=min(alpha(1,i,times)*W*max((Q(1,i,timeIndex) - T(1,i,timeIndex))*tau/(0.693*V*w) - N0/GAMA(1,i,timeIndex),0),pimax); end end c = 1 - nc*eps; for i = 1:N if Q(1,i,timeIndex) > T(1,i,timeIndex) lambdal(1,i,times) = (Q(1,i,timeIndex) - T(1,i,timeIndex))*((W*tau*log((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*c) + 1))/log(2) - (GAMA(1,i,timeIndex)*Ptx(1,i,times)*tau)/(N0*c*log(2)*((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*c) + 1))); lambdau(1,i,times) = (Q(1,i,timeIndex) - T(1,i,timeIndex))*((W*tau*log((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*eps) + 1))/log(2) - (GAMA(1,i,timeIndex)*Ptx(1,i,times)*tau)/(N0*eps*log(2)*((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*eps) + 1))); else lambdal(1,i,times) = 0; lambdau(1,i,times) = 0; end end lambdaL=max(lambdal(1,:,times));lambdaU=max(lambdau(1,:,times)); xi = 10^(-7);l=0;Imax = 200; x1 = 0;x2 = 1 - nc*eps;F = 1;time = 1; for i = 1:N alpha3(1,i) = alpha2(1,i,times); end while(abs(sum(alpha3)+sum(alpha1(1,:,times))-1) >= xi & (l <= Imax)) l = l +1; lambda = 0.5*(lambdaL + lambdaU); for i = 1:N if lambda > 0 if i + nc == N x = 1 - sum(alpha3(1,1:i-1)) - nc*eps; end if GAMA(1,i,timeIndex)*Ptx(1,i,times) > 0 F1 = abs(lambda-(Q(1,i,timeIndex) - T(1,i,timeIndex))*((W*tau*log((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x1) + 1))/log(2) - (GAMA(1,i,timeIndex)*Ptx(1,i,times)*tau)/(N0*x1*log(2)*((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x1) + 1)))); F2 = abs(lambda-(Q(1,i,timeIndex) - T(1,i,timeIndex))*((W*tau*log((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x2) + 1))/log(2) - (GAMA(1,i,timeIndex)*Ptx(1,i,times)*tau)/(N0*x2*log(2)*((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x2) + 1)))); x = 0.5*(x1 + x2); F3= abs(lambda-(Q(1,i,timeIndex) - T(1,i,timeIndex))*((W*tau*log((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x) + 1))/log(2) - (GAMA(1,i,timeIndex)*Ptx(1,i,times)*tau)/(N0*x*log(2)*((GAMA(1,i,timeIndex)*Ptx(1,i,times))/(N0*W*x) + 1)))); if F3 < F1 x2 = x; else x1 = x; end end alpha3(1,i) = max(eps,x); else alpha3(1,i) = eps; end end if sum(alpha3) > 1 - sum(alpha1(1,:,times)) lambdaL =lambda; else lambdaU = lambda; end end if times > 1 gains = abs(Ptx(1,i,times) - Ptx(1,i,times - 1)); end times = times + 1; for i = 1:N alpha2(1,i,times) = alpha3(1,i); end end for i = 1:N ptx(1,i,timeIndex) = Ptx(1,i,times - 1); end for i = 1:N Alpha(1,i,timeIndex) = alpha1(1,i,times - 1) + alpha2(1,i,times); end for i = 1:N Dr(1,i,timeIndex) = Alpha(1,i,timeIndex)*W*tau*log2(1 + GAMA(1,i,timeIndex)*ptx(1,i,timeIndex)/(Alpha(1,i,timeIndex)*N0*W)); end for i = 1:M fc(1,i,timeIndex) = fcmax; end for i = 1:M pser(1,i,timeIndex) = k*fc(1,i,timeIndex)^3; end ds = max(T(1,:,timeIndex)); for i = 1:N if T(1,i,timeIndex) == ds Ds(1,i,timeIndex) = sum(fc(1,:,timeIndex)*tau)/Li; else Ds(1,i,timeIndex) = 0; end end Psum(timeIndex) =w*(sum(ptx(1,:,timeIndex)) + sum(pl(1,:,timeIndex))); for i = 1:N Q(1,i,timeIndex +1) = max(Q(1,i,timeIndex) - Dl(1,i,timeIndex) - Dr(1,i,timeIndex),0) + A(1,i,timeIndex); end for i = 1:N T(1,i,timeIndex +1) = max(T(1,i,timeIndex) - Ds(1,i,timeIndex) ,0) + min(max(Q(1,i,timeIndex) - Dl(1,i,timeIndex),0),Dr(1,i,timeIndex)); end end average_enery(m) = sum(Psum)/500; end plot(Z,average_enery,'o-');
评论
    相关推荐