MuPAD:如何确定一组线性不等式的解是否存在? [英] MuPAD: How to determine just the existence of solutions to a set of linear inequalities?

查看:24
本文介绍了MuPAD:如何确定一组线性不等式的解是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 MuPAD,我想找出对于一组线性不等式是否存在至少一个解决方案.例如,以下线性不等式系统:

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:

我在 MuPAD 中通过以下方式解决:

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}

并且 MuPAD 以某种符号形式返回解决方案集:

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

然而,我不关心解决方案集的确切形式,即它是有限的还是无限的,我只关心是否至少有一个可行的解决方案.

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.

我想从 Matlab 调用 MuPAD,询问是否存在不等式的解集,然后得到是"或否"的答案.我可以测试返回的空集,但我不知道如何测试符号变量是否代表空集.

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.

推荐答案

这是一个使用 MuPAD 的示例 solvesym/isempty 从 Matlab 调用:

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]))

第一种情况返回true,1,说明至少有一个解.第二个返回 false,0,因为没有解决方案.

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

如果您想在 MuPAD 中执行此操作,您可以使用 函数:

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])={}))

但是,第一种情况将返回 UNKNOWN,这个比较难处理.您可能希望使用以下内容:

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)

假设只有一个空的解决方案Ø,才会有一个长度为一.(MuPAD 代码是两个字符,{},但它显示为 1,Ø,长度为 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.

这篇关于MuPAD:如何确定一组线性不等式的解是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆