在 Sympy 中解决不等式 [英] Solving Inequalities in Sympy
问题描述
我试图在 sympy 中解决以下不等式:
(10000/x) - 1 <0
于是我发出命令:
solve_poly_inequality( Poly((10000/x) - 1 ), '<')
但是,我得到了:
[Interval.open(-oo, 1/10000)]
然而,我的手动计算给出了 x <0 或 x >10000.
我错过了什么?由于 -1,我无法将其表示为有理函数.
提前致谢!
您正在使用低级求解例程.我建议使用更高级别的例程 solve
或 solveset
,例如
您的尝试是正确但看起来错误的原因是您没有指定要使用的生成器,因此 Poly 使用 1/x
作为其变量(我们称之为 g
>) 所以它解决了问题 1000*g - 1 <0
...当 g 小于您发现的 1/1000 时为真.
你可以通过书写看到这个生成器标识
<预><代码>>>>聚(1000/x - 1)Poly(1000*1/x - 1, 1/x, domain='ZZ')I tried to solve the following inequality in sympy:
(10000 / x) - 1 < 0
So I issued the command:
solve_poly_inequality( Poly((10000 / x) - 1 ), '<')
However, I got:
[Interval.open(-oo, 1/10000)]
However, my manual computations give either x < 0 or x > 10000.
What am I missing? Due to the -1, I cannot represent it as a rational function.
Thanks in advance!
You are using a low-level solving routine. I would recommend using the higher-level routines solve
or solveset
, e.g.
>>> solveset((10000 / x) - 1 < 0, x, S.Reals)
(−∞, 0) ∪ (10000, ∞)
The reason that your attempt is right but looks wrong is that you did not specify the generator to use so Poly used 1/x
as its variable (let's call it g
) so it solved the problem 1000*g - 1 < 0
...which is true when g is less than 1/1000 as you found.
You can see this generator identification by writing
>>> Poly(1000/x - 1)
Poly(1000*1/x - 1, 1/x, domain='ZZ')
这篇关于在 Sympy 中解决不等式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!