My objective function is in for


(Mostafa Pasandideh) #1

Hello
I want to minimize my objective function in loop, but I cant.


I receive this, and I don’t know why, because all of the variable and parameters are specific.

Untitled
Error using cvxprob/newobj (line 24)
An objective has already been supplied for this problem.

Error in minimize (line 21)
newobj( prob, ‘minimize’, x );

Error in Untitled (line 10)
minimize(P(t,m));


(Mark L. Stone) #2

You can only specify one optimization problem between cvx_begin and cvx_end, and therefore can have only one minimize or maximize statement between cvx_begin and cvx_end. Your program has h = 50 minimize statements.

Are you trying to solve h different minimization problems? If so, then you should have the for t = 1:h outside the cvxx_begin … cvx_end. Then there will be only one optimization problem, which has one minimize statement, inside of each cvx_begin … cvx_end.

If, on the other hand, you wish to solve only one minimization problem, but such that the objective is a sum, for instance, minimize(sum(P(:,m)), then put that outside the for t=1:h loop, and before the cvx_end.


(Mostafa Pasandideh) #3

Thanks a lot ,you reply my question so fast :slight_smile: thank you.