Search code examples
matlabsymbolic-mathsimplexmupad

MuPAD: How to determine just the existence of solutions to a set of linear inequalities?


Using MuPAD, I want to find out if at least one solution exists for a set of of linear inequalities. For example, the following system of linear inequalities:

enter image description here

which I solve in MuPAD by:

solve({x+z>2*y,z>y,2*z>2*x,x>0,y>0,z>0},{x,y,z}

and MuPAD returns the set of solutions, in some type of notation:

enter image description here

However, I do not care about the exact form of the solution set, i.e., whether it is finite, or infinite, I just care if there is at least one viable solution.

I would like to call MuPAD from Matlab, ask if a solution set exists to the inequalities, and then get back a "yes" or "no" answer. I could test for the empty set being returned, but I do not know how to test if a symbolic variable represents the empty set.


Solution

  • Here's an example using MuPAD's solve and sym/isempty called from Matlab:

    syms x y z;
    ~isempty(feval(symengine,'solve',[x+z>2*y,z>y,2*z>2*x,x>0,y>0,z>0],[x y z]))
    ~isempty(feval(symengine,'solve',[x+z>2*y,z>y,2*z>2*x,x>0,y>0,z<0],[x y z]))
    

    The first case returns true, 1, indicating that there is at least one solution. The second returns false, 0, as there is no solution.

    If you want to do this within MuPAD, you can use the is function:

    not(is(solve([x+z>2*y,z>y,2*z>2*x,x>0,y>0,z>0],[x,y,z])={}))
    not(is(solve([x+z>2*y,z>y,2*z>2*x,x>0,y>0,z<0],[x,y,z])={}))
    

    However, the first case will return UNKNOWN, which is rather difficult to deal with. You may want to use something like the following instead:

    is(length(solve([x+z>2*y,z>y,2*z>2*x,x>0,y>0,z>0],[x,y,z]))>1)
    is(length(solve([x+z>2*y,z>y,2*z>2*x,x>0,y>0,z<0],[x,y,z]))>1)
    

    which assumes that only an empty solution, Ø, will have a length of one. (The MuPAD code is two characters, {}, but it displays as one, Ø, has a length of one, and means empty/zero.) There are probably other ways.