借助sympy.xreplace()
方法,我们可以将变量x替换为数学表达式中函数的任何其他变量,而无需通过使用来编辑整个表达式sympy.xreplace()
方法。
用法:sympy.xreplace()
返回:Return the replaced value of x in the mathematical expression.
范例1:
在这个例子中,我们可以通过使用sympy.xreplace()
方法,我们可以替换表达式中数学函数的x变量并返回更新后的表达式。
# import sympy
from sympy import *
x, y = symbols('x y')
f = sin(x) + cos(2 * x)
# Use sympy.xreplace() method
gfg = f.xreplace({2 * x:y})
print(gfg)
输出:
sin(x) + cos(y)
范例2:
# import sympy
from sympy import *
x, y = symbols('x y')
f = log(sin(x)) + tan(cos(2 * x))
# Use sympy.xreplace() method
gfg = f.xreplace({ x:2 * y})
print(gfg)
输出:
log(sin(2*y)) + tan(cos(4*y))
相关用法
- Python next()用法及代码示例
- Python os.dup()用法及代码示例
- Python set()用法及代码示例
- Python Decimal max()用法及代码示例
- Python PIL ImageOps.fit()用法及代码示例
- Python os.rmdir()用法及代码示例
- Python sympy.det()用法及代码示例
- Python Decimal min()用法及代码示例
- Python os.readlink()用法及代码示例
- Python os.writev()用法及代码示例
- Python os.readv()用法及代码示例
- Python PIL RankFilter()用法及代码示例
- Python os.rename()用法及代码示例
- Python os.sendfile()用法及代码示例
注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python | sympy.xreplace() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。