How can I express 1/x^2 as a convex function using DCP rules?

(Let’s say I want to solve the following problem:

cvx_begin

variables x

minimize 1/x

subject to

1<=x<=2

cvx_end)

How can I express 1/x^2 as a convex function using DCP rules?

(Let’s say I want to solve the following problem:

cvx_begin

variables x

minimize 1/x

subject to

1<=x<=2

cvx_end)

You can use `inv_pos(x)`

or `pow_p(x,-1)`

for 1/x,

or use `pow_p(x,-2)`

or `square(inv_pos(x))`

for 1/x^2.

This is addressed in the CVX Users Guide http://cvxr.com/cvx/doc/funcref.html#new-functions .

Edit: As discussed below, `square(inv_pos(x))`

is valid under CVX 3.0beta, but not under CVX 2.1.

Thanks a lot.

pow_p(x,-2) works fine!

(However square(inv_pos(x)) produces the error Illegal operation: square( {convex} )).

Sorry about that. `square(inv_pos(x))`

works under CVX 3.0beta which is more “lenient” (sophisticated) on sign-dependent matters, but not under CVX 2.1. `square_pos(inv_pos(x)`

) should work under both CVX 2.1 and 3.0 beta. As well, of course, as `pow_p(x,-2)`

.

I have another question and I would be grateful if you could help:

Even though x/(x+1)^2 is not convex on the whole real line, it can be shown that it is convex for x>=2.

How can i formulate let’s say the following problem in CVX?

‘minimize x/(x+1)^2

subject to 2<=x<=3’

I don;t see how to do it. Convexity (or concavity) only over a restricted range is often not possible to deal with in CVX. But I’m not saying it definitely can’t be done. So I’ll leave your question at X/(x+1)^2 convex for x>=2 open, so that someone can weigh in more definitively.

Edit: My suspicion is confirmed by mcg’s answer at the linked question.

How can we write X\Y? is it correct to write it as inv_pos(X)*Y ???

No.

Perhaps if you show the entirety of your problem, someone can help.

Are you trying to specify a vector `c`

as a solution of `X*c = Y`

? If so, and if `X`

is an input matrix and not a CVX variable or expression, then include the constraint `X*c == Y`

, then use `c`

elsewhere in your program however you want, so long as in compliance with CVX’s DCP rules. If `X`

and `c`

are both CVX variables or expressions, that constraint would be non-convex and not allowed.