借助sympy.coeff(x, n)
方法,我們能夠找到數學表達式中的變量係數。
用法:sympy.coeff(x, n)
返回:Return the coefficient of variables.
範例1:
在這個例子中,我們可以通過使用sympy.coeff(x, n)
方法,我們可以找到數學表達式的係數。
# import sympy
from sympy import * x, y, z = symbols('x y z')
gfg_exp = x * y + x - 3 + 2 * x**2 - z * x**2 + x**3
# Using sympy.coeff(x, n) method
gfg_exp = gfg_exp.coeff(x, 2)
print(gfg_exp)
輸出:
2 - z
範例2:
# import sympy
from sympy import * x, y, z = symbols('x y z')
gfg_exp = z * x + x - 3 + 2 * x**2 - y * x**2 + y**3
# Using sympy.coeff(x, n) method
gfg_exp = gfg_exp.coeff(y, 1)
print(gfg_exp)
輸出:
-x**2
相關用法
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python next()用法及代碼示例
- Python Decimal ln()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python isinstance()用法及代碼示例
- Python Numpy np.fft()用法及代碼示例
- Python os.symlink()用法及代碼示例
- Python os.access()用法及代碼示例
- Python os.link()用法及代碼示例
- Python os.mkfifo()用法及代碼示例
- Python os.sched_rr_get_interval()用法及代碼示例
- Python sympy.lcm()用法及代碼示例
注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | sympy.coeff(x, n) method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。