小编Eri*_*sen的帖子

sympy 中的实值假设

我正在尝试在 sympy 中创建实值变量,因为只有实部并且不复杂,没有虚部。我使用的是 sympy 1.0、IPython 5.3.0 和 Python 2.7.13。

In [48]: x = Symbol('x', real=True)
In [49]: x.assumptions0
Out[49]: 
{'commutative': True, 
  'complex': True, 
  'hermitian': True, 
  'imaginary': False, 
  'real': True}
In [50]: x * conjugate(x)
Out[50]: 
 2
x 
Run Code Online (Sandbox Code Playgroud)

结果是正确的,但它同时表示complexrealare True,这让我担心未来的结果。如果我试图让它真实但不复杂,我会得到:

In [51]: x = Symbol('x', real=True, complex=False)
---------------------------------------------------------------------------
InconsistentAssumptions                   Traceback (most recent call last)
Run Code Online (Sandbox Code Playgroud)

然后是一堆回溯信息。显然,这些假设在某种程度上相互冲突,我一定是误解了它们的含义。

如果我试图确保complex=False我得到:

In [52]: x = Symbol('x', complex=False)
In [53]: x.assumptions0
Out[53]: 
{'algebraic': False,
 'commutative': True,
 'complex': False,
 'composite': False, …
Run Code Online (Sandbox Code Playgroud)

python sympy

5
推荐指数
1
解决办法
3327
查看次数

标签 统计

python ×1

sympy ×1