Error inusing prod_inv(x)

(jiangxu) #1

My program is
variables x(2)
minimize inv_pos(x(1)) + inv_pos(x(2)) + prod_inv(x)
subject to

But the error occurs

Undefined function or variable ‘n’

cvx/prod_inv (line 37)
geo_mean( cat( dim, x, y ), dim, [ ones(n,1) ; p ] ) >= 1; %#ok

minimize (line 14)
x = evalin( ‘caller’, sprintf( '%s ', varargin{:} ) );

cvx_test (line 5)
minimize inv_pos(x(1)) + inv_pos(x(2)) + prod_inv(x)"

So how can I use prod_inv(x) correctly?

(Mark L. Stone) #2

This is a bug in prod_inv . The 3rd argument in the call to geo_mean should not be [ ones(n,1) ; p ] . In your case, given that you are not using a 3rd argument of prod_inv, i.e., a non-default value of p, the 3rd argument in the call to geo_mean can be eliminated, and it will work.

(jiangxu) #3

Do you mean that I can change the line “geo_mean( cat( dim, x, y ), dim, [ ones(n,1) ; p ] ) >= 1; %#ok” to “geo_mean( cat( dim, x, y ), dim) >= 1; %#ok” in the prod_inv.m file?

(Mark L. Stone) #4

I think that will work “correctly” as long as you do not call prod_inv with 3 arguments (you only used one argument). However, it is not the correct general fix.

help prod_inv

prod_inv inverse of the product of a positive vector.
For a real vector, matrix, or X, prod_inv(X) returns 1.0 ./ PROD(X) if
the elements of X are all positive, and +Inf otherwise.

For matrices, prod_inv(X) is a row vector containing the inverse
product of each column of X. For N-D arrays, prod_inv(X) is an array of
inverse products taken along the first non-singleton dimension of X.

prod_inv(X,DIM) takes inverse products along the dimension DIM of X.

prod_inv(X,DIM,P), where P is a positive real constant, computes
prod_inv(X).^P. This is slightly more efficient than the equivalent

Disciplined convex programming information:
    prod_inv(X) is convex and nonincreasing in X; therefore, when used
    in CVX specifications, its argument must be concave or affine.

(jiangxu) #5

Thank you.

In the CVX’s user guide, it only gives the one argument case. I think one argument is sufficient for me to use CVX