Interpolation error

Hi,Mark.

There is a piecewise function:

y=6.961e-05*x+4.433e-04;%0<=x<=63.505
y=1.657e-06*x^2-1.322e-04*x+0.0065761;%63.505<=x<=87

(This piece function is successive at 63.505 beceuse I approximate some coefficients to express easily. )
And I do not know how to express it in cvx.
and it can not be expressed by the form of max(6.961e-05x+4.433e-04,y0)+max(1.657e-06x^2-1.322e-04*x+0.0065761,y0)-y0,because the quadratic function have some values that exceed y0 when x is between 0 and 63.505.(y0 is the value of the piece function in 63.505.)
Thank you.

The quadratic piece is concave, so I assume you will maximize the piecewise function or use it in a >= constant inequality. Therefore, model the hypograph, y >= t of the piecewise function, and then use t in place of y in your program. In order to do this, you can implement

if x <= 63.505t
then 
  t <=1st formula for y
else
  t  <= 2nd formula for y

Implement this logic construct by introducing binary with big (enough) M, using something similar to the Expressing Logical Constraints slides of https://www.cs.upc.edu/~erodri/webpage/cps/theory/lp/milp/slides.pdf .

I leave you to make sure this is correct, and to work out the details.

Note:The small magnitude coefficients in your formulation might cause numerical difficulties, and are best avoided by re-scaling or some other means.

The quadratic piece is convex,because 1.657e-06>0.And the piecewise function is convex.

Sorry, I misread that. Just change
t <=
to
t >=

By the way, if you have a better solution, you are welcome to use it.

Thank you,Mark.
In fact,the piecewise function is obtained by many data such as (xi,yi),and I just want to fit these data to a function.
In addition,I found a better way that is from

So I have solved this question.
Thank you very much.

Hi,Mark.
Could you please help me to change the form of
z=0.005*abs(y) exp(14.4 abs(y)/x) and x>100,-3<=y<=3, so that cvx can accept it?
Thank you very much.

This appears to be convex, but I don’t see how ti implement it in CVX. Your last hope probably is that one of the Mosek guys can figure out how to do it, and if not, it’s a candidate for @Erling’s challenge.

Note that the related function, y*exp(y) is not convex for y < -2, and therefore is not convex over its “natural” domain. I do not know any way of implementing that in CVX even for y restricted to be >= -2 (or 0).

The function abs(y)*exp(abs(y)/x), although apparently convex for all y and x, would appear to be no easier, and perhaps more difficult, to implement in CVX than y*exp(y) for y >= -2.

If y\geq 0 then a model for t\geq y\exp(y) is essentially in https://docs.mosek.com/modeling-cookbook/expo.html#lambert-w-function, equation (5.10), up to renaming variables. Throwing in x we get the following model for t\geq y\exp(y/x), x,y\geq 0:

t\geq y\exp(u/y)
ux\geq y^2

The first one is an exponential cone the other is rotated quadratic.

Now in general it should be OK to replace y with a positive z with z\geq |y| but frankly I haven’t checked all the correct monotonicity details. Either it works or I don’t see another way.

1 Like

Son of a bitch. i don’t know how I missed that. And I just posted a comment on the Lambert W function a couple of weeks ago, linking to a post on this forum by @Erling. .

Suggestion, include Lambert W in the next version of Conic Modeling Cheatsheet.

In the function of z=0.005*abs(y) exp(14.4 abs(y)/x),x,y and z are N-dimensional vectors(such as N=100). And I want to know how to use exponential cone when variables are N-dimensional vectors.
Thank you.

Id x(i), y(i), z(i) are constrained in an exponential cone for each value of i, use a for loop

for i=1:N
{x(i),y(i),z(i)} == exponential(1)
end

And follow the advice at CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions

Thank you,Mark.
Using a for loop may lead to increase the running time of the program,but there seems to be no better way.