# How to use qld function without the error message

**URL:** <https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432>\
**Category:** Optimization\
**Created:** [March 18, 2024, 2:15pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432 "2024-03-18T14:15:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![FUJIMOTO](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@FUJIMOTO](https://scilab.discourse.group/u/FUJIMOTO)\
**Post date:** [March 18, 2024, 2:15pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/1 "2024-03-18T14:15:32Z")

</div>

I have a convex polyhedral cone defined as \{Ax,x\geq 0\}. I want to determine whether a point y lies in this cone. To do so, I solve the following linear programming problem:

\begin{align\*} \operatorname{Minimize}&: (x\_1 + x\_2 + ...+ x\_n) \\ \text{Subject to}&:\\ x &\geq 0,\\ y - Ax &= 0. \end{align\*}

The existence of a feasible solution in the linear programming problem is equivalent to y belongs to the convex polyhedral cone \{Ax,x\geq 0\}.  
The point y = (-1, -1)^\top is not a point in the convex polyhedral cone when A = I.  
Solving the Linear Programming Problem: Let’s solve the following linear programming problem:

```Scilab
Q=zeros(2,2);
p=[1;1];
b=-[1;1];
C=eye(2,2);
ci=[0;0];
cs=[];
me=2;
[x ,lagr ,info] = qld(Q, p, C, b, ci, cs, me )

```

However, it currently stops with the error message:

```auto
qld: The constraints are inconsistent.

```

Desired Outcome: I expect the solver to return info == 10 and I want to continue the conditional branches based on the value of info.  
How can I proceed the code without the error message and stopping the execution?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 18, 2024, 3:01pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/2 "2024-03-18T15:01:59Z")

</div>

Hello,

You are right, when 3 output arguments are provided no error should be raised, can you create an issue at [Issues · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/issues) ?

In the meantime, if you just need an information on feasibility, could you use karmarkar ([karmarkar - Solves a linear optimization problem.](https://help.scilab.org/karmarkar)) ?

```Scilab
p=[1;1]
b=-[1;1]
A=eye(2,2);
[xopt,fopt,exitflag]=karmarkar(A,b,p);
exitflag

--> exitflag
 exitflag = 

  -1.

```

-1 means no feasible solution.

S.

---

<div class="post-metadata">

**Author:** ![FUJIMOTO](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@FUJIMOTO](https://scilab.discourse.group/u/FUJIMOTO)\
**Post date:** [March 19, 2024, 7:31am UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/3 "2024-03-19T07:31:00Z")

</div>

Mr. mottelet.  
I greatly appreciate your advice !  
When I ran the simulation karmarkar worked fine for many parameters, but I got error messages “karmarkar: Wrong value for input argument #4. x0 does not satisfy the equality constraints.” for the following parameters.Is there a solution to avoid the error?

Aeq=[  
1,1,-1,-1,0;  
0,1,1,0,-1;  
-1,-1,-1,-1,-1  
]

beq=[  
0;  
1;  
-1  
]

f=[1,1,1,1,1]

[xopt,fopt,exitflag]=karmarkar(Aeq,beq,f)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 19, 2024, 8:21am UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/4 "2024-03-19T08:21:17Z")

</div>

To solve your feasibiity problem (until qld is fixed, likely in next version of Scilab), you can use qp\_solve (not qpsolve, which cannot work in silent mode). Since qp\_solve does not accept bounds you just have to reshape the x\geq 0 constraint as a general linear constraint. For example in the above case

```scilab
A = [1,1,-1,-1,0;
   0,1,1,0,-1;
  -1,-1,-1,-1,-1];
y = [0;1;-1];

[m,n] = size(A);
Q = eye(n,n);
p = zeros(n,1);
C = [A;eye(n,n)]';
b = [y;zeros(n,1)];
[x,i,iter,f,info] = qp_solve(Q,p,C,b,m)

```

you get the minimum norm positive x and info==0:

```auto
 x = 

   1.850D-17
   0.5000000
   0.5
   5.136D-34
  -3.772D-33
 i = 

   2.
   8.
   1.
   7.
   3.
   0.
   0.
   0.
 iter = 

   6.
   0.
 f = 

   0.25
 info = 

   0.

```

and for the trivial case you gave at the begining of the topic:

```scilab
A = eye(2,2);
y = [-1;-1];

[m,n] = size(A);
Q = eye(n,n);
p = zeros(n,1);
C = [A;eye(n,n)]';
b = [y;zeros(n,1)];
[x,i,iter,f,info] = qp_solve(Q,p,C,b,m)

```

you get a warning and info==1:

```auto
qp_solve: Warning: The minimization problem has no solution. The results may be inaccurate.

 x = 

  -1.
  -1.
 i = 

   1.
   2.
   0.
   0.
 iter = 

   3.
   0.
 f = 

   1.
 info = 

   1.

```

---

<div class="post-metadata">

**Author:** ![FUJIMOTO](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@FUJIMOTO](https://scilab.discourse.group/u/FUJIMOTO)\
**Post date:** [March 19, 2024, 10:01am UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/5 "2024-03-19T10:01:44Z")

</div>

Dear Stephen,  
I execute your suggested code.But I have error message as follows:  
“karmarkar: Wrong value for input argument #4. x0 is not positive.”

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 19, 2024, 10:12am UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/6 "2024-03-19T10:12:06Z")

</div>

karmarkar seems also broken (see [karmarkar fails solving trivial problem (#17227) · Issues · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/issues/17227)), use qp\_solve instead (see my above answer).

S.

---

<div class="post-metadata">

**Author:** ![FUJIMOTO](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@FUJIMOTO](https://scilab.discourse.group/u/FUJIMOTO)\
**Post date:** [March 19, 2024, 3:16pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/7 "2024-03-19T15:16:17Z")

</div>

Dear mottelet,  
Thanks a lot to your reply.  
I could run the simulation successfully. But whenever an infeasible solution is found, I receive warning messages:  
“qp\_solve: Warning: The minimization problem has no solution. The results may be inaccurate.”  
Is there any way not to display this message?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 19, 2024, 3:17pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/8 "2024-03-19T15:17:17Z")

</div>

You can suppress the warnings with:

```scilab
warning("off")

```

S.

---

<div class="post-metadata">

**Author:** ![FUJIMOTO](https://avatars.discourse-cdn.com/v4/letter/f/eb8c5e/32.png) [@FUJIMOTO](https://scilab.discourse.group/u/FUJIMOTO)\
**Post date:** [March 23, 2024, 2:17pm UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/9 "2024-03-23T14:17:42Z")

</div>

I think the description of the matrix C in the help file of `qp_solve` is incorrect. The help file suggests multiplying matrix C from the left by an `n`-dimensional column vector `x`,  
x^\top C(:,j)=b(j)  
but the dimensions of `x` and the number of rows in `C` (which is `me+md`) do not match. When I set up `C` as per the help file,

> C = [A;eye(n,n)]’ //same as help instruction

I encountered the following error:

> qp\_solve: Wrong value for input argument #5: me must be an integer in the range 0 to 2.

I believe the correct formula involves multiplying `x` from the right.  
C(:,j)x=b(j)  
and right code according to this interpretation

> C = [A;eye(n,n)]

However, I received a different error message.

> qp\_solve: Wrong value for input argument #5: me must be an integer in the range 0 to 2.

Since the number of columns in `C` is 2, there shouldn’t be an error, but I can’t figure out the cause.Please tell me a solution.

```auto
A =[1,1;2,1;3,2;4,1]
y = [5;2;3;2];

[m,n] = size(A);
Q = eye(n,n);
p = zeros(n,1);
C = [A;eye(n,n)]' //same as help instruction
//C = [A;eye(n,n)]; //right formula
disp("size(C)",size(C))
b = [y;zeros(n,1)];
[x,i,iter,f,info] = qp_solve(Q,p,C,b,m)
disp(info)

```

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [March 25, 2024, 8:23am UTC](https://scilab.discourse.group/t/how-to-use-qld-function-without-the-error-message/432/10 "2024-03-25T08:23:33Z")

</div>

Hello,

In an optimisation problem you cannot have more equalities constraints than the dimension of the unknown, which is 2 in your case (2 non redundant equality constraints already uniquely determine the solution). That’s why qld complains.

When there are less generating vectors that the dimension of the space, testing wether a given vector is in the cone cannot be made with a linear program.

If I understand your example, the cone \mathcal{C} you are considering is a subset of \mathbb{R}^4 since y=(5,2,3,2)^\top and is generated as the positive span of vectors

a\_1=(1,2,3,4)^\top,\quad a\_2=(1,1,2,1)^\top.

In that case you have less generating vectors (2) than the dimension of the space (4), so testing weither y is a positive combination of these two vectors should be made first by verifying that y is actually in \operatorname{span (a\_1,a\_2)}. For example you can check the rank of matrix (a\_1,a\_2,y):

```scilab
-> M = [1 2 3 4;1 1 2 1;5 2 3 2]'
 M = 

   1. 1. 5.
   2. 1. 2.
   3. 2. 3.
   4. 1. 2.

--> rank(M)
 ans =

   3.

```

here the rank is 3 so y is not a combination of a\_1 and a\_2, hence does not belong to the cone. If we test another vector, e.g. z=(2,3,5,5)^\top, we have

```scilab
--> M = [1 2 3 4;1 1 2 1;2 3 5 5]'
 M = 

   1. 1. 2.
   2. 1. 3.
   3. 2. 5.
   4. 1. 5.

--> rank(M)
 ans =

   2.

```

hence z belongs to \operatorname{span (a\_1,a\_2)} and the coefficients are uniquely obtained with

```scilab
--> [1 2 3 4;1 1 2 1]'\[2 3 5 5]'
 ans =

   1.0000000
   1.0000000

```

S.
