我不懂同情,但我想解决以下问题:
有多个不等式约束的形式
A < f(x) < B
C < g(x) < D
...其中A,B,C,D只是数字。F和g是有理函数。
例如,我可以让以下内容发挥作用:
solve_rational_inequalities([[
((Poly(x-10000.00), Poly(1, x)), '>'),
((Poly(x-100000.00), Poly(1, x)), '<'),
((Poly((x/130000.00)-0.00), Poly(1, x)), '>'),
((Poly((x/130000.00)-0.19), Poly(1, x)), '<')]])
Interval.open(10000, 24700)这里,A= 10.000,B= 100.000,C= 0,D= 0.19,f(x) =x,g(x) = x/130.000。所以这是可行的。
现在,对于另一种情况,函数f( x ) = 10100.00 /x。
如果我把上面的食谱应用到上面,我会得到:
solve_rational_inequalities([[
((Poly((10100.00/x)-0.00), Poly(1, x)), '>'),
((Poly((10100.00/x)-0.19), Poly(1, x)), '<')]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/oliverdemetz/Library/Python/2.7/lib/python/site-packages/sympy/solvers/inequalities.py", line 162, in solve_rational_inequalities
numer_intervals = solve_poly_inequality(numer*denom, rel)
File "/Users/oliverdemetz/Library/Python/2.7/lib/python/site-packages/sympy/solvers/inequalities.py", line 55, in solve_poly_inequality
reals, intervals = poly.real_roots(multiple=False), []
File "/Users/oliverdemetz/Library/Python/2.7/lib/python/site-packages/sympy/polys/polytools.py", line 3454, in real_roots
reals = sympy.polys.rootoftools.CRootOf.real_roots(f, radicals=radicals)
File "/Users/oliverdemetz/Library/Python/2.7/lib/python/site-packages/sympy/polys/rootoftools.py", line 196, in real_roots
return cls._get_roots("_real_roots", poly, radicals)
File "/Users/oliverdemetz/Library/Python/2.7/lib/python/site-packages/sympy/polys/rootoftools.py", line 565, in _get_roots
raise PolynomialError("only univariate polynomials are allowed")
sympy.polys.polyerrors.PolynomialError: only univariate polynomials are allowed发布于 2018-01-15 17:22:34
我只是用多项式搅乱了有理函数。我在寻找的是solve_poly_inequalities
solve_poly_inequalities(((
(Poly((10100.00/x)-0.00),'>'),
(Poly((10100.00/x)-0.19),'<')
)))顺便说一句:谁能告诉我(作为phython初学者)他们为什么对列表使用((...)),尽管手册将方括号[...]解释为列表语法?
无论如何,我终于解决了使用solveset命令解决不平等的实际问题,请参阅this other SO post。
发布于 2018-01-15 21:08:48
在solve_rational_inequality()语法中,第一个多项式( poly )是分子,第二个多项式是分母,因此(1/x)在这个语法中是poly(1,x), poly(x):
solve_rational_inequalities([[((poly(-10100.00,x), poly(x)), '>'),((poly(-0.19*x+10100.00), poly(x)), '<')]])
(-oo, 0)
https://stackoverflow.com/questions/48266247
复制相似问题