I still recommend what I wrote in my previous reply.
Nevertheless don’t know whether this would do what you need or whether it will work. Use polyfit separately on the two regions of xx to fit the quadratic and linear approximations, but do so outside CVX, i.e., just use polyfit as intended in MATLAB. Then take the two fitted pieces, and implement them in CVX via use of Big M modeling to define the piecewise function (if xx <=… then fitted_quadratic. else fitted_linear). https://www.fico.com/en/resource-download-file/3217 will show you how to do that… I don;t understand what you are doing with Jsunhao, so I don’t know if it will work out and even be accepted by CVX, but it looks to me like it won’t work.
Mark,I understood your meaning.
In a word, I can not use polyfit in cvx directly to convert a expression which contains variables to a quadratic function(such as yy=0.9483*abs(xx).exp(14.3841inv_pos(nb)*xx).
A CVX variable or expression cannot be an argument of polyfit.
As far as the approach of using polyfit outside of CVX, as mentioned in my immediately preceding post, the reason I am not sure it would not work, is because if your piecewise function, ffitted outside CVX, were implemented in CVX using xx as a CVX variable, and then multiplied by terms in another CVX variable, dE, that would be non-convex and not allowed in CVX. But if your final function to be minimized is a function of only a single CVX variable, then perhaps it could be done. As I have said, I am confused what you are doing with Jsunhao.
If I do not polyfit expression yy to a quadratic function in advance in cvx,the objective function Jsunhao(N) will contain two variables(dE(N) and nb) which is the form of ‘yy=0.9483*abs(dE).exp(14.3841inv_pos(nb)*dE)’.
And as I wrote, multiplying CVX expressions is non-convex and is not allowed. So that would not work.
I will end this thread by repeating my advice to abandon CVX for this problem, and use a nonlinear non-convex optimizer, in which case you are probably better off letting the optimizer handle the original function, than fitting a piecewise quadratic, linear function. CVX has its place, but not for this problem.
(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.)
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
t <=1st formula for y
t <= 2nd formula for y
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.
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.