How to substitute multiple symbols in an expression in sympy?

后端 未结 3 1594
我寻月下人不归
我寻月下人不归 2020-12-11 00:38

Assigning a variable directly does not modify expressions that used the variable retroactively.

>>> from sympy import Symbol
>>> x = Symbol         


        
3条回答
  •  星月不相逢
    2020-12-11 01:31

    The command x = Symbol('x') stores Sympy's Symbol('x') into Python's variable x. The Sympy expression f that you create afterwards does contain Symbol('x'), not the Python variable x.

    When you reassign x = 0, the Python variable x is set to zero, and is no longer related to Symbol('x'). This has no effect on the Sympy expression, which still contains Symbol('x').

    This is best explained in this page of the Sympy documentation: http://docs.sympy.org/latest/gotchas.html#variables

    What you want to do is f.subs(x,0), as said in other answers.

提交回复
热议问题