0

I have a simple question. How do I use the command qpsolve from Scilab if I only want to use the lower bounds and upper bounds limit?

   ci  <= x <= cs

The command can be used as this:

   [x [,iact [,iter [,f]]]] = qpsolve(Q,p,C,b,ci,cs,me)

But I want to use it like this:

   x = qpsolve(Q,p,[],[],ci,cs,[])

Only ci and cs should explain the limits for vector x. Unfortunately, the command cannot take empty []. Should I take [] as a row vector of ones or zeros?

https://help.scilab.org/docs/6.0.1/en_US/qpsolve.html

euraad
  • 2,467
  • 5
  • 30
  • 51

1 Answers1

1

In Scilab 5.5.1 , [] works for C and b but not for me. so C = [];b = [];me = 0; should work.

Why

qpsolve is an interface for qp_solve :

function [x, iact, iter, f]=qpsolve(Q,p,C,b,ci,cs,me)

    rhs = argn(2);
    if rhs <> 7
        error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"), "qpsolve", 7));
    end
    C(me+1:$, :) = -C(me+1:$, :);
    b(me+1:$) = -b(me+1:$);
    // replace boundary contraints by linear constraints
    Cb = []; bb = [];
    if ci <> [] then
        Cb = [Cb; speye(Q)]
        bb = [bb; ci]
    end
    if cs <> [] then
        Cb = [Cb; -speye(Q)]
        bb = [bb; -cs]
    end
    C = [C; Cb]; b = [b; bb]
    [x, iact, iter, f] = qp_solve(Q, -p, C', b, me)

endfunction

It transform every bound constraints into linear constraints. To begin, it swap the sign of the inequality constraints. To do that, it must know me, ie it must be an integer. Since C and b are empty matrices, is value doesn't matter.

Bonus:

if Q is inversible, you could skip the qpsolve macro and write

x = -Q\p
x(x<ci) = ci(x<ci)
x(x>cs) = cs(x>cs)
Community
  • 1
  • 1
PTRK
  • 899
  • 1
  • 5
  • 18
  • for me, this works: x = qp_solve(eye(n,n), v(n,1), zeros(n, 1), [0], 0), where v is a vector of dimension n. – euraad Jul 24 '18 at 12:15