我有一个方程式,我试图解决。我使用SymPy实时控制台获得了正确的结果,该控制台可以在他们的网站上找到。然而,当我试图在我的本地计算机上重现相同的结果时,我得到generateNewOne
并且我无法解决这个问题。
完全相同的等式无法在本地求解。我不确定分区是否有问题(但我导入ConditionSet
),缺少LaTex库或其他一些设置?
以下是来自SymPy live的命令:
__future__.division
打印在LaTex中的结果:
Python console for SymPy 1.0 (Python 2.7.12)
These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)
Warning: this shell runs with SymPy 1.0 and so examples pulled from other documentation may provide unexpected results.
Documentation can be found at http://docs.sympy.org/1.0.
>>> a = Eq(309.07*(1+x)**(-1/12) + 309.07*(1+x)**(-2/12)+309.07*(1+x)**(-3/12) + 309.07*(1+x)**(-4/12) + 309.07*(1+x)**(-5/12) + 309.07*(1+x)**(-6/12) + 309.07*(1+x)**(-7/12), 1500)
>>> solveset(a, x, domain=S.Reals)
这里是本地python脚本:
{2.17102109654962}
以ASCII文本打印的结果:
from __future__ import division
from sympy import *
init_printing()
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
a = Eq(309.07*(1+x)**(-1/12) + 309.07*(1+x)**(-2/12)+309.07*(1+x)**(-3/12) + 309.07*(1+x)**(-4/12) + 309.07*(1+x)**(-5/12) + 309.07*(1+x)**(-6/12) + 309.07*(1+x)**(-7/12), 1500)
b = solveset(a, x, S.Reals)
print b
我正在使用ConditionSet(x, Eq(309.07*(x + 1)**(-0.583333333333333) + 309.07*(x + 1)**(-0.5) + 309.07*(x + 1)**(-0.416666666666667) + 309.07*(x + 1)**(-0.333333333333333) + 309.07*(x + 1)**(-0.25) + 309.07*(x + 1)**(-0.166666666666667) + 309.07*(x + 1)**(-0.0833333333333333) - 1500, 0), (-oo, oo))
和Python 2.7
我将不胜感激任何帮助...
答案 0 :(得分:0)
我不确定导致不同行为的原因,但是如果你告诉同意将你的指数视为同情整数,那么你将得到与SymPy Live相同的结果:
from __future__ import division
from sympy import *
init_printing()
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
a = Eq(309.07*(1+x)**(-1/Integer(12)) + 309.07*(1+x)** (-2/Integer(12))+309.07*(1+x)**(-3/Integer(12)) + 309.07*(1+x)**(-4/Integer(12)) + 309.07*(1+x)**(-5/Integer(12)) + 309.07*(1+x)**(-6/Integer(12)) + 309.07*(1+x)**(-7/Integer(12)), 1500)
b = solveset(a, x, S.Reals)
print b
至于为什么python整数不被视为本地安装中的sympy Integers,我不知道。对我而言,似乎SymPy Live会覆盖/
运算符。要澄清此行为,请尝试
print(type(1/12))
在本地安装和SymPy Live中。本地结果为<class 'float'>
,SymPy Live结果为<class 'sympy.core.numbers.Rational'>
。