hello

I have a vector **(x)** with 25*1. I want to separate this vector to 5 vectors with 5*1 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

cvx_begin

variable x(25,1 ) complex

for kx=1:5

fg=x(5*(kx-1)+1:kx*5);

f2(:,kx) =diag(fg)*A(:,kx);

end

minimize(sum_square_abs(y-diag(f2)*A) );% % this is my cost function

cvx_end

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)