How to find argmax in a cvx block in matlab?

557 Views Asked by At

I am trying to find the argmax inside a cvx block in matlab. This is just to find the optimal policy for the Bellman equation using linear programming. In the code below if I just do:

k = max(Q)

It finds the maximum of the list Q and works fine, but as soon as I do:

[k y] = max(Q)

To find the argmax of list Q, it complains:

??? Error using ==> cvx.max
Too many output arguments.

Is there a different way of finding argmax in cvx?

cvx_begin
variable V(N)
minimize(sum(V))

subject to
for s=1:N
    for a=1:A
        for s_next=1:N
            tmp(s_next) = mdp.T{a}(s,s_next)*(mdp.R{a}(s,s_next) + mdp.gamma*V(s_next));
        end
        Q(a) = sum(tmp);
        V(s) >= sum(tmp);
    end
    [k y]=max(Q)
end  
cvx_end
1

There are 1 best solutions below

0
On

So I ended up using dual variables to find the optimal policy. I am still not sure if there is a way of finding argmax inside cvx.