借助sympy.expand()
方法,我們可以通過使用變量形式擴展數學表達式sympy.expand()
方法。
用法:sympy.expand(expression)
返回:Return mathematical expression.
範例1:
在這個例子中,我們可以通過使用sympy.expand()
方法,我們可以獲得帶變量的數學表達式。在這裏我們用symbols()
方法還可以將變量聲明為符號。
# import sympy
from sympy import expand, symbols
x, y = symbols('x y')
gfg_exp = x + y
# Use sympy.expand() method
exp = sympy.expand(gfg_exp**2)
print(exp)
輸出:
x**2 + 2*x*y + y**2
範例2:
# import sympy
from sympy import expand, symbols
x, y, z = symbols('x y z')
gfg_exp = x + y + z
# Use sympy.expand() method
exp = sympy.expand(gfg_exp**2)
print(exp)
輸出:
x**2 + 2*x*y + 2*x*z + y**2 + 2*y*z + z**2
相關用法
- Python set()用法及代碼示例
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python getattr()用法及代碼示例
- Python os.getpgrp()用法及代碼示例
- Python os.fork()用法及代碼示例
- Python os.nice()用法及代碼示例
- Python os.getsid()用法及代碼示例
- Python os.setregid()用法及代碼示例
- Python os.pwrite()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | sympy.expand() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。