# Subs/replace command in CVX

Hi all,

I haven’t used CVX in a while, so sorry if this question is basic.
I would like to define, say, a polynomial function p=c_1x_1^2+c_2x_1x_2+c_3x_2^3, where the c_i's are decision variables, but the x_i's are not. I then need access to point evaluations of this polynomial, which would be linear expressions in the coefficients c_i. For example, I want to impose a constraint p(1,2)>5. How do you do this?

Thanks,
-Amirali

The comment section doesn’t seem to give me enough space, so I respond to mcg’s comment here:

Not sure if I completely understand the comment; I don’t want to write p in a separate function. Let me elaborate on my question. If I was doing this, e.g., in YALMIP, I would write:

sdpvar c_1 \ c_2\ c_3\ x_1 \ x_2

p=c_1x_1^2+c_2x_1x_2+c_3x_2^2

replace(p,[x_1,x_2],[1,2])>5 %this would be my constraint

Then, when calling the solver, I would let it know that the decision variables are c_1, c_2, c_3 (and not x_1 and x_2). So I am asking in CVX, (i) how do you distinguish between decision variables and indeterminate variables, and (ii) what is the analogue of the “replace” command above?

Perhaps there is no such special functionality and you are saying that I should use native MATLAB commands?

Suppose you were doing this inside a function, and c is passed in as a numeric vector. How would you evaluate p there?

“I don’t want to write p in a separate function.” I understand that. But it’s an exercise: if you can express what you’re trying to do with a standard MATLAB function, it will show you how to do it in CVX. CVX does not have an equivalent to YALMIP’s “replace” function, or indeterminate variables.

For the record I never recommend that people switch from YALMIP to CVX if they are already comfortable with YALMIP. I happen to think CVX is easier to use for what it does, but YALMIP does more.

Thanks, mcg. Of course, I didn’t mean to bring up a yalmip vs. cvx issue - I think they are both wonderful at what they do. It was just a way of expressing my question more concretely.

Is there a fundamental reason why CVX chooses not to allow indeterminate variables? (They can often make the code much shorter. Consider, e.g., something as simple as fitting a polynomial function to data.)

It’s not a matter of “allowing” them or not. CVX simply doesn’t implement that kind of processing.