Using fit model in CVX programming


I want to use a 2-D look-up table (given x,y result in z) in my CVX programming, I tried to use a cubic interpolant fitted function instead ( z=f(x,y) ) of this table but it is not described in standard form. Is it possible to use the fit model directly in CVX?


Not if any of the arguments are CVX variables or expressions.

If you have a fit model, obtained by whatever means, its use in a CVX program must be in compliance with its rules. Therefore, it is necessary (but not sufficient) that the fit model, considered as a function of any CVX variables, must be jointly convex or concave in those variables, or there is no possibility of using it in CVX.

You might be able to use handle some piecewise functions, as described in the “Mosek Modeling Cookbook” or “FICO MIP formulations and linearizations Quick reference” Some of these constructs require introduction of binary variables, which can be declared in CVX (MIDCP capability), but without availability of higher level constructs such as SOS2 (which you would need to model “manually”).

Also please read

Hello again,

thank you very much for your response, I tried to use a second order fit model to approximate the data points I need to use, the function looks like this, and it is convex:
Linear model Poly22:
f(x,y) = p00 + p10x + p01y + p20x^2 + p11xy + p02y^2
Coefficients (with 95% confidence bounds):*
p00 = -89.42 (-90.04, -88.79)*
p10 = -0.01323 (-0.01462, -0.01184)*
p01 = -0.004337 (-0.009499, 0.0008256)*
p20 = 9.902e-06 (8.992e-06, 1.081e-05)*
p11 = -1.442e-05 (-1.743e-05, -1.142e-05)*
p02 = 4.393e-05 (3.125e-05, 5.661e-05)*

so I tried to use it in my constraints as (e is a variable) :

e(i) == -(p00 + p10x(i) + p01y(i) + p20x(i).^2 + p11x(i).y(i) + p02y(i).^2)

and I get this error:
Disciplined convex programming error:
Invalid constraint: {real affine} == {convex}

Shouldn’t I be able to use convex constraints in cvx? I got confused can you advice me with that ?


Both sides of equality constraints in CVX must be affine. Please read . The right-hand side of your equality constraint is not affine, although it is convex.

You haven’t shown how you intend to use this in your program, but I suspect this can be done via assignment, using = rather than =='). Please read .

1 Like

You were absolutely right!
I changed ‘e’ from variable into expression and changed ‘==’ to ‘=’ and it works now, thank you very much the link was very useful.