借助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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
