Writing an expression to a power of vector

(Salwa Mostafa) #1

Hi , I want to write this objective function but I have a problem with writing d as it should be a vector from 1 to S and q is the vector I optimize
This is the expression and q represent m/n

Untitled

\sum^S_{d=1} \sum^N_{j=1} \gamma_d * P_j *(1 - q)^d

The optimization variable is q = m_j / n and all the other variables are inputs

M = 100 ; N = 5 ; S = 10; P_j  = [ .5 ,  .1 ,  .2 , .3 , .4 ] , gammad = [.1 : .1: 1]

cvx_begin
         variable q(N)
         minimize(sum(sum(gammad'*P_j* (1 -  q)^(1:S))))
         subject to
         sum(q) ==  M ;
         0 <= q <= 100;
     cvx_end

minimize(sum(sum(gammad’ * Pj.*(1 - q).^d)))

I tried to use this minimize(sum(sum(gammad’Pj (bsxfun(@power , (1 - q), (1:S))’)))) but still give error

(Mark L. Stone) #2

You haven’t told us what are decision (optimization) variables vs. input data.

Nevertheless, have you tried pow_p? Its first argument can be a vector or matrix, to which the power is applied elementwise.

(Salwa Mostafa) #3

I have updated the post.

(Mark L. Stone) #4

Try using pow_p with a fixed value of d, and use a for loop to sum over the values of d I’ll let you work out the details. Or I believe you can just use ^ in this manner instead of pow_p.

(Salwa Mostafa) #5

N = 5
M = 100
S = 10
P_j = [ .5 , .1 , .2 , .3 , .4 ] ,
\gamma_d = [.1 : .1: 1]
cvx_begin
variable q(N)

            for  i = 1 : S
                
                Total(1:length(q),i) = (pow_p( (1 - q ) , i ))' ;
                
            end     

     minimize (sum(sum ((P_j'*\gamma_d)*Total)))
               
     subject to
     sum(q) ==  M ;
     0 <= q <= 1;

 cvx_end

I tried to write it in this form but the output is NaN and I cannot figure out where is the problem. Can you please help.

(Mark L. Stone) #6

Please show clean MATLAB/CVX code not a bastardized mix of MATLAB/CVX and Latex/Mathjax which makes it impossible to know what you ran. Presuming your code \gamma_d is really gamma_d, your objective function is not even dimensionally consistent.

(Salwa Mostafa) #7

Thanks so much for your response. I wrote the matlab code below. The issue now is that the optimized value q is NaN

N = 5
M = 100;
S = 10;
P = [ .1 .2 .3 .4 .6]
gammad = [.1:.1:1]

cvx_begin

variable q(N)

        for  i = 1 : S
            
            Total(1:length(q),i) = (pow_p( (1 - q ) , i ))' ;
            
        end     

 minimize (sum(sum ((P'*gammad)*Total')))
           
 subject to
 sum(q) ==  M ;
 0 <= q <= 1;

cvx_end

(Mark L. Stone) #8

The problem is infeasible.

q has 5 elements. Given that each element of q <= 1, the maximum possible value of sum(q) is 5, thereby rendering sum(q) == 100 impossible to achieve,

(Salwa Mostafa) #9

Okay . Thanks I got where is the error. Thanks so much. I worked it out now