There is my program:

a1=0.076;a2=0.064;b1=0.0032;b2=0.0035;d1=-7.27;d2=3.086;
cvx_solver sedumi
cvx_begin
variable x(10001);
variable y;
expression f1(10000);
expression f2(10000);
expression J(10000);
expression dx(10000);
dx=x(2:10001)-x(1:10000);
J=max(f1,f2);
minimize(sum(J));
subject to

110<=y<=290;

cvx_end

I want to express a function about J=(dx.^2)/y.And what I want to do is let the J=(dx.^2)/y can be accepted by cvx.

Am I right in my program about quad_over_lin because dx is a N-dimension?

Thank you.

Your program is accepted by CVX.

quad_over_lin Sum of squares over linear.
Z=quad_over_lin(X,Y), where X is a vector and Y is a scalar, is equal to
SUM(ABS(X).^2)./Y if Y is positive, and +Inf otherwise. Y must be real.

``````If X is a matrix, quad_over_lin(X,Y) is a row vector containing the values
of quad_over_lin applied to each column. If X is an N-D array, the operation
is applied to the first non-singleton dimension of X.

quad_over_lin(X,Y,DIM) takes the sum along the dimension DIM of X.
A special value of DIM == 0 is accepted here, which is automatically
replaced with DIM == NDIMS(X) + 1. This has the effect of eliminating
the sum; thus quad_over_lin( X, Y, NDIMS(X) + 1 ) = ABS( X ).^2 ./ Y.

In all cases, Y must be compatible in the same sense as ./ with the squared
sum; that is, Y must be a scalar or the same size as SUM(ABS(X).^2,DIM).

Disciplined convex programming information:
quad_over_lin is convex, nonmontonic in X, and nonincreasing in Y.
Thus when used with CVX expressions, X must be convex (or affine)
and Y must be concave (or affine).``````
1 Like

Thank you,Mark.
And I also want to know how I can express the quad_over_lin in my question.

You know what you want better than I do. If you provide numerical inputs (MATLAB variables rather than CVX variables or expressions) into `quad_over_lin`, and you get the answer you want, then it should be correct when you do the same thing with CVX variables or expressions.

I am sorry,Mark.I don’t seem to understand you.
Do you want me to provide my program code？

In your code, where you have
`variables x(4) y`
change it to `X=[3;6.2;1;5];y=7;`
etc.
If `quad_over_lin` evaluates to the number you want, it should work correctly when you change back to declaring CVX variables.

Yes,Mark.In my program,x and dx both are column vector:

variable x(10001);
variable y;
expression dx(10000);

We can see from here that dx and x are column vectors and y is a scalar(y>0).
These are in line with what you just said.
But when I use quad_over_lin(dx,y) in f1and f2,there seems to be something wrong with the program running.

The program you showed is accepted by CVX. Does it not produce the answer you want? Try an example with short length vectors, so you can see exactly what it is doing.

You can also remove all the `expression` declarations from your program. They don’t do anything useful for this program. Despite your declarations, `f1, f2, J` all evaluate to scalars. Perhaps you are not understanding that `quad_over_lin` does summation of the individual quadratic over linear terms.Therefore `J1` and `J2` are scalars, and therefore `J` is a scalar. Therefore, `sum(J)` is the same as `J`. Read the help in my earlier post.

Yes,Mark.I can not get correct result.
But I change the quad_over_lin(dx,y) to quad_over_lin(dx,y,2),this seems to get the right result.
Mark,Do you know the reason?

O.k. I think I see what is going on. It wasn’t obvious to me what you were trying to do. The 3rd argumennt with value 2 causes quad_over_lin to only sum across rows, of which there is only one, thereby producing a column vector. That then goes into the max which is picking out the larger of J1 and J2 per row. Then the winners are summed. However, given that the only difference between f1 and f2 are the multiplication constants a1 and a2, I don’t see why the result would be different, within solver tolerance, vs. not having the 3rd argument of quad_over_lin with value 2.

I am sorry,Mark. I simplified the formula for the convenience of explanation. Now I supplement the two formulas about f1 and f2.
And I want to know if I’m doing this right about quad_over_lin(dx,y,2) .

That produces an unsummed column vector of square over linear terms. It’s up to you what you want.

The original formula is：
f1=a1 *(dx.^2)/y+b1 *abs(dx)+d1;
f2=a2 *(dx.^2)/y+b2 *abs(dx)+d2 *square(y);
J=max(f1,f2);
minimize(sum(J));
In this formula,dx is a 10000-dimension column vector,and y is a scalar(y>0).
And I want let this formula can be accepted by cvx.

The program as you have now written it is accepted by CVX. However, it appears you want the 3rd argument, 2, of quad_over_lin. And you don’t need the expression declarations. SO the following program is accepted… Is this what you want?

``````a1=0.076;a2=0.064;b1=0.0032;b2=0.0035;d1=-7.27;d2=3.086;
cvx_solver sedumi
cvx_begin
variable x(10001);
variable y;
dx=x(2:10001)-x(1:10000);