MATLAB Answers

how to take whole matrix using loop index

5 views (last 30 days)
wasif shabir
wasif shabir on 19 Sep 2020
Commented: wasif shabir on 19 Sep 2020
whilw solving alernate optimzation problem, i am having issue with takiing whole matrix using loop. i have two matrices for example W=6*6 and theta1=6*6,
maximize(real(trace( theta1(i)*Hs*W(i)*Hs' )))
now i have to take whole matrices not elements like W and theta1 should be 6*6.
kindly some one help i am stuck here.

  0 Comments

Sign in to comment.

Answers (1)

Vinicius Pereira Mateus Borges
I am not sure if I understand the question. Please attach some of your data and code as an example if the following does not help:
1) Instead of using a for loop, can you not just do element-wise multiplication between the matrices?
maximize(real(trace( theta1 .* Hs .* W * Hs' ))) % assuming Hs is a constant
2) If Hs is a changing part of a for loop, then you two options:
% double indexing with i and j for rows and colums
for i = 1:6
for j = 1:6
maximize(real(trace( theta1(i,j)*Hs*W(i,j)*Hs' )))
end
end
% using linear indexing (so counting between 1:36)
for i = 1:36 % works for a 6 by 6 matrix, but you may want to soft code this
maximize(real(trace( theta1(i)*Hs*W(i)*Hs' )))
end
You may want to look at how linear indexing works before using the second option. For instance, in a 6-by-6 matrix, theta1(7) would be the first element of the second row (same as theta1(1,2)).

  1 Comment

wasif shabir
wasif shabir on 19 Sep 2020
i have complex matrices for all hs, theta1 and W, in ist itration i have taken W with all one matrix, using all one W in prob#1 i have to find optimizte theta1(i) and then this theta1(i) is used in next prb#2 to get optimize W(i+1). my question is that this is itrative process and what should do to get a theta1 and W as matrices not an elements.
for i=1:1:100
%%prob#1
cvx_begin sdp
variable theta1(L+1,L+1) complex semidefinite
maximize(real(trace( theta1(i)*Hs*W(i)*Hs' )))
subject to
real(trace(theta1(i)*Hpk*W(i)*Hpk'))<=gamma_k;
for t=1:L+1
real(theta1(t,t))<=1;
end
%theta1(i) == semidefinite(L+1);
cvx_end
%% prob#2
cvx_begin sdp
variable W(M,M) complex semidefinite
maximize(real(trace( theta1(i)*Hs*W(i+1)*Hs' )))
subject to
real(trace(theta1(i,j)*Hpk*W(i+1,j+1)*Hpk'))<=gamma_k;
real(trace(W(i+1))<=P;
%W(i+1) == semidefinite(M);
cvx_end
%%etta is a factor =0.
etta(i+1)=trace(theta1(i)*Hs*W(i+1)*Hs');
tol_factor is also a scalar value
if real(etta(i+1,))-real(etta(i)<=tol_factor
break;
else
i=i+1;
j=j+1;
end
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by