Incorrect values when calculating the optimum value using while loop
2 views (last 30 days)
Show older comments
Dear all,
Please I'm trying to get the optimum power allocation Pk using while loop.. but it seems that I wrongly writing this algorithm and all values are equal to 1 without making alot of iterations... please can any one help me to correct the code.. I appreciate your help.
This is my code:
%parameters
TN=10
lamda=[5.3899,2.8511,1.0846,0.4003,2.8364,0.0988,0.0470,0.3417,0.5460,0.5992];
segma_squared=10^-9; %variance
tau=0.1;
Pt=1;
beta= [0.3414,0.1707,0.1138,0.0854,0.0683,0.0569,0.0488,0.0427,0.0379,0.0341];
epsilon=0.001
%%%%%%%%%%%starting of algorithm 1%%%%%%%%%%%%%%%
max_iterations=1000;
power_allocation_initial=[5.3899,4.435,1.1024,0.4004,2.854,0.109988,0.0470,0.3417,0.3450,0.6592];
for i=2:max_iterations
for k=1:TN
gamma_infinity(i,k)=(lamda(k)*(1-tau^2)*power_allocation_initial(k)*Pt)/(segma_squared); % calculation initial value of gamma_inf(0)
w_k(k)=log2(power_allocation_initial(k));
while (gamma_infinity(i,k)-gamma_infinity(i-1,k) >= epsilon)
i=i+1;
gamma_infinity(i,k)=gamma_infinity(i-1,k);
k_(k)=(gamma_infinity(i,k))/(1+gamma_infinity(i,k));
v_k(k)=log2(1+gamma_infinity(i,k))-((gamma_infinity(i,k))/(1+gamma_infinity(i,k)))*log2(gamma_infinity(i,k));
eita_wk(i,k)=-k_(k) *w_k(k)-k_(k)*log2(lamda(k)*(1-tau^2))*Pt + 2*k_(k)*log2(sqrt(segma_squared))-v_k(k);
w(i,k)=beta(k)*eita_wk(i,k);
ww(i)=sum(w(i,k));
[p_opt(k),fval] = linprog(ww(i),[],[],[],[],0,1);
end
end
end
6 Comments
Torsten
on 20 Nov 2022
Edited: Torsten
on 20 Nov 2022
Don't you see from the description of the algorithm that the optimization problem has to be solved within the while-loop and not outside ?
And now that you search for a vector p of length 10, your upper and lower bounds also have to be vectors of length 10. But you set them to 0 and 1 - so just one value.
And what is the for-loop good for ? Isn't it a superfluous duplicate of the while-loop ?
Accepted Answer
Torsten
on 20 Nov 2022
Edited: Torsten
on 21 Nov 2022
With regards to for loop, I used it to be able to do j-1 as a previous step
But the steps (variable i) are done in the while loop - so no further for loop is needed.
I don't understand the underlying problem. Here is a suggestion for code as I understand the algorithm (although problem (25) is quite strange since the extra terms (2nd and 3rd) in the definition of Gamma don't depend on the optimization variable omega):
TN=10;
lamda=[5.3899,2.8511,1.0846,0.4003,2.8364,0.0988,0.0470,0.3417,0.5460,0.5992];
segma_squared=10^-9; %variance
tau=0.1;
Pt=1;
beta= [0.3414,0.1707,0.1138,0.0854,0.0683,0.0569,0.0488,0.0427,0.0379,0.0341];
epsilon=0.001;
power_allocation_initial=[5.3899,4.435,1.1024,0.4004,2.854,0.109988,0.0470,0.3417,0.3450,0.6592];
gamma_infinity_im1=(lamda.*(1-tau^2).*power_allocation_initial*Pt)/(segma_squared); % calculation initial value of gamma_inf(0)
imax = 20;
i = 0;
error = 1;
while error > epsilon && i < imax
i = i+1;
kappa = gamma_infinity_im1./(1+gamma_infinity_im1);
v = log2(1+gamma_infinity_im1)-kappa.*log2(gamma_infinity_im1);
f = -beta.*kappa; % Don't know if there are other terms in gamma(omega) that depend on p except the first
omega = linprog(f,[],[],[],[],-Inf(10,1),log2(Pt)*ones(10,1));
P = 2.^omega
gamma_infinity_i = lamda.*(1-tau^2).*P.'*Pt/segma_squared;
error = sum(abs(gamma_infinity_im1-gamma_infinity_i))
gamma_infinity_im1 = gamma_infinity_i;
end
3 Comments
Torsten
on 21 Nov 2022
I'm quite sure we both still don't understand the model correctly.
So I suggest you let the MATLAB code pause for a while and read the background article from which the algorithm was developed again carefully.
Do you have a link to the article in question ?
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!