Index of variable

(Ebi Ebi) #1

I have a vector (x) with 251. I want to separate this vector to 5 vectors with 51 and then do multiplication with a matrix (A) and then calculate sum then cost function is obtained.
Unfortualey that vector (x) is my variable and when I use loop with for I got error because I want to index the variable that is defined after cvx_begin .what do you suggest for defining cost function in this situation?

x : is 25 by 1
y : is 5 by 1
xi : is 5 by 1
matrix A is 5 by 5
A(:,i): i’th coulmn of matrix A
cost function : minimize (y-sum(diag(xi)*A(:,i))) %% summation is done over all i
variable x

variable x(25,1 ) complex
for kx=1:5
f2(:,kx) =diag(fg)*A(:,kx);
minimize(sum_square_abs(y-diag(f2)*A) );% % this is my cost function

for solving this problem I used CVX command for saving variable and then I write loop command it worked but I do not know this is correct or not ? because I need index of variable.
some posts related to this topic. in simple way how can I index the variable after define them for making cost function I hope this help .(with simple example)

(Mark L. Stone) #2

You need to get dimensions of all your MATLAB and CVX variables to be consistent (conformal), which they currently are not,

Write out all assignments and expressions (including objective function) as though they are in MATLAB without CVX. Get everything consistent (conformal). Then re-write, declaring whatever you need as CVX variables (for instance maybe x is 25 by 1).

(Ebi Ebi) #4

This is the practical problem I did not formulate in that way.
I am waiting for your ans.

(Mark L. Stone) #5

If in the objective function, you change
y - diag(f2)*A
y - A*diag(f2)
your program is confomal and will be accepted by CVX. I have no idea whether that correctly implements what you want to implement.

(Mark L. Stone) #6

Regarding the link Finding it hard to model this objective function in CVX , did you try doing what the OP did?