Incorrect values when calculating the optimum value using while loop

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 Kommentare

It would be helpful to know what problem (25) is.
Thanks alot Torsten, I updated it and inerted problem 25
You do the same mistake as before:
You try to decouple the problem and minimize one single ww(k):
[p_opt(k),fval] = linprog(ww(i),[],[],[],[],0,1);
although you are told to minimize sum(beta_k*gamma(ww(k))
So in short: Delete the loop over k - all values p(k) for k in K (so the complete vector p) have to be determined simulaneously by solving your optimization problem.
bassant tolba
bassant tolba am 20 Nov. 2022
Bearbeitet: bassant tolba am 20 Nov. 2022
Dear Torsten,
Thank you really for your reply. I modified the last two lines, but it says that the solution is unbounded and there is no values for p_opt
%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);
end
end
ww=sum(w);
[p_opt,fval] = linprog(ww,[],[],[],[],0,1);
end
Torsten
Torsten am 20 Nov. 2022
Bearbeitet: Torsten am 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 ?
Dear Torsten,
please can you kindly let me know by code, how to modify my code as I got confused sorry..
With regards to for loop, I used it to be able to do j-1 as a previous step

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Torsten
Torsten am 20 Nov. 2022
Bearbeitet: Torsten am 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
Optimal solution found.
P = 10×1
1 1 1 1 1 1 1 1 1 1
error = 3.9584e+10
Optimal solution found.
P = 10×1
1 1 1 1 1 1 1 1 1 1
error = 0

3 Kommentare

Yeah your answer is correct ..thanks alot.. but, due to kappa and v are dependent on power in gamma_infinity so they are implicitly depend on omega as well. Thus, the objective function f should be = beta.*(-kappa * omega)- kappa* log2(lamda)*(1-tau^2)*Pt+2*kappa*log2(segma)-v
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 ?
yes sure,
here is the link for the article.
Really, I'm grateful for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by