0

I am trying to use Disciplined Convex Programming (CVX) to solve a family of optimization problems in Matlab. But I keep getting the error

the || and && operators must be convertible to logical scalar values".

I have tried replacing the equality constraints with two inequality constraints, but the problem persists.

For some parameter values, this problem goes away and the problem is solved successfully, but I have not been able to figure out a pattern.

Any help solving this problem, or understanding what's causing it would be much appreciated.

x = linspace(0,200,1001)';
fL = lognpdf(x,2,1);
fH = lognpdf(x,3,1);
cc = (max(x)-min(x))/1001;
cvx_begin 
variable V(1001,1)
maximize( cc.*sum((x-V.^2).*fH) + G_L(vL).*cc.*sum((x-V.^2).*fL) )
subject to
    cc.*sum(V.*fH) == 0.8;
    cc.*sum(V.*fL) == 0.2;
    V >= 0;
cvx_end
Operands to the || and && operators must be convertible to logical scalar values.

Error in checkdepconstr (line 88)
if (numdencol > 0) && (printlevel)
Error in HSDsqlpmain (line 135)
    checkdepconstr(blk,At,b,y,rmdepconstr);
Error in sdpt3 (line 277)
      HSDsqlpmain(blk3,At3,C3,b,par,X03,y0,Z03);
Error in cvx_run_solver (line 56)
   [ varargout{1:nargout} ] = sfunc( inputs{:} );
Error in cvx_sdpt3>solve (line 288)
    [ obj, xx, y, zz, info ] = cvx_run_solver( @sdpt3, blk, Avec, Cvec, b, OPTIONS,
    'obj', 'x', 'y', 'z', 'info', 5, params ); %#ok
Error in cvx_solve (line 399)
            [ x, status, tprec, iters, y ] = shim.solve( At, b, c, cones, params );
Error in cvx_finish
Error in cvx_end (line 11)
    evalin( 'caller', 'cvx_finish' );
Argyll
  • 8,591
  • 4
  • 25
  • 46
  • What do you mean by `V >= 0`? Each element greater than zero? You may have to specify that individually. Otherwise, consult your package help page. (It may help to link it.) It does not appear to be a native Matlab function. – Argyll Sep 01 '19 at 19:07
  • Yes - each element greater than zero. In CVX, that's a typical way to impose constraints. That said, I can remove this constraint, and I get the same error message. :( – George Georgiadis Sep 02 '19 at 00:23
  • As a starter, it helps to link the package you are using. – Argyll Sep 02 '19 at 03:42
  • Thanks Argyll. It's CVX - http://cvxr.com/cvx/ – George Georgiadis Sep 02 '19 at 19:11
  • At a quick glance, you indeed have to explicitly specify the inequality constrain per element. See [here](http://web.cvxr.com/cvx/doc/basics.html#constraints). You can either generate the code with a different script. Or you can try phrasing your per-element constraint as I\*V>0, where I is identity matrix of appropriate size and 0 is zero vector of appropriate size. You can then try converting I*V>0 to [comma separated list](https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html) possibly via `mat2cell`. etc – Argyll Sep 02 '19 at 19:52
  • Ofc, I wouldn't bother with all that unless the rest of your code works. So I would generate the inequality constraints with a different script for now. In the documentation section I linked, you can see the description of how the package you are using treats multiple constraints. The `Operands to the || and && operators must be convertible to logical scalar values.` error means you have non-scalar operands passed to either `||` or `&&` operators. See [here](https://www.mathworks.com/help/matlab/ref/logicaloperatorsshortcircuit.html). – Argyll Sep 02 '19 at 19:53

0 Answers0