How to solve a division of constant and variable? e.g. A/X

#1

Let \mathbf{A} = [1,2,\ldots, A] of size 1\times N and \mathbf{X} = [1,2,\ldots, X] of size 1\times N. The optimization variable is \mathbf{X}.

The optimization problem is defined as \text{minimize} \sum_{i=1}^{N} A_i/X_i.
Two constraints are: X_i>=0 and \sum_{i=1}^{N} X= X_{\text{max}}.
I am unable to write it in CVX.

(Erling D.Andersen) #2

This is a trivial problem so what did you try that did not work?

#3
clear all
n=10;
A = randn(1,n);

cvx_begin
    variable x(1,n);
    minimize((A./x));
    subject to
        sum(x)>1;
        x>0;
cvx_end

Disciplined convex programming error:
Cannot perform the operation: {mixed negative constant/positive constant} ./ {real affine}

Error in ./ (line 19)
z = times( x, y, ‘./’ );

(Erling D.Andersen) #4

If you look in the documentation you will find a function called

inv_pos()

that can be used to do what you want. See

http://web.cvxr.com/cvx/doc/funcref.html#nonlinear

#5

Thank you, I tried the following:

n=10;
A = randi([1 10],1,n);

cvx_begin
    variable x(1,n) nonnegative
    minimize(A.*inv_pos(x));
    subject to
        sum(x)>=1;  
cvx_end

I get the following error as:

Error using class
Cannot change the number of fields of class ‘cvxtuple’ without first typing ‘clear classes’.

Error in cvxtuple (line 19)
v = class( struct( ‘value_’, { v }, ‘dual_’, { [] } ), ‘cvxtuple’, cvxobj );

Error in cvx_end (line 185)
assignin( ‘caller’, ‘cvx_optpnt’, cvxtuple( cvx_collapse( vars, false, false ) ) );

Error in geo_mean_cone (line 355)
cvx_end

Error in cvx/pow_cvx (line 158)
{ cat( nd, cvx_accept_concave(xt), yt ), 1 } == geo_mean_cone( sw, nd, [-pt,1], ‘func’ ); %#ok

Error in cvx/inv_pos (line 5)
y = pow_cvx( x, -1, ‘pow_p’ );

Error in test (line 8)
minimize(A.*inv_pos(x));

#6

Thank you, I forget to see the clear classes. It works perfectly.

#7

The correct code:

clear all
clear classes

n=10;
A = randi([1 10],1,n);

cvx_begin
    variable x(1,n) nonnegative
    minimize(sum(A.*inv_pos(x)));
    subject to
        sum(x)<=1;  
cvx_end
x