Question regarding writing a function for optimization

Dear All

I hope that you are all fine

I would like to ask if I can use CVX to optimize an equation that contains many nested summations. Normally I do the summations using for loops in Matlab so I don’t know if I can CVX as an optimizer.

A very simple example of nested summations is
Max Sum(1:No of years)(Sum(1:No of weeks)(x+y)))


It may be nicest if you can declare matrix or vector variables and form your objective with single or nested sum not requiring for loops. However, you can declare an expression and build up your objective function in (possibly nested) for loops if needed; then presuming S is your expression, use the command maximize(S). This should be clear if you read the CVX User’s Guide.

Thanks for your answer

Can you refer where I can find some information about this issue in the CVX manual???

I suggest you read the whole manual … seriously, it’s not very long. Pay particular attention to the section on assignment and expression holders. But if you don’t understand other material, you won’t understand that either.

I see no reason why you cannot use for loops to do the summations. They will be slow but you would not be the first to use them.

But how I can maximize the whole equation if I did the for loops,
I mean assume that S=Sum(1:No of years)(Sum(1:No of weeks)(x+y)))
and I want to maximize S, How can I do that?