hello
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
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)
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).
If in the objective function, you change y - diag(f2)*A
to 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.