2017-06-04 26 views
0

我有一個方程我試圖解決。 SymPy live控制檯可以在他們的網站上獲得正確的結果。然而,當我試圖在本地計算機上重現相同的結果時,我得到了一個ConditionSet,我無法解決方程式。本地vs SymPy live的不同結果 - 分裂問題?

完全相同的等式不能在本地求解。我不確定是否可能出現錯誤(但我正在導入__future__.division),缺少LaTex庫或其他設置?

下面是SymPy命令住:

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) 

結果打印乳膠:

  {2.17102109654962} 

在這裏,當地的python腳本:

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 

結果打印在ASCII文本:

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.7SymPy 1.0 我將不勝感激任何幫助......

+0

也許Sympy Live使用Sympy的開發版本?在任何情況下,使用'solve'而不是'solveset'給出答案。然而,當你在尋找一個數值解決方案時,使用'nsolve'是最好的選擇,因爲它會使(相同)結果快得多。 – Stelios

回答

0

我不知道是什麼原因導致不同的行爲,但如果你告訴sympy對待你的指數爲sympy整數,然後你會得到相同的結果與SymPy直播:

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 

至於爲何蟒整數像sympy整數當地治療不及時安裝,我不知道。對我來說,好像SymPy Live覆蓋了/運營商。要澄清此行爲,請嘗試

print(type(1/12)) 

在您的本地安裝和SymPy Live中。本地結果將爲<class 'float'>,SymPy Live結果將爲<class 'sympy.core.numbers.Rational'>