當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sympy.expand_trig()用法及代碼示例

借助sympy.expand_trig(expn)方法,我們能夠擴展三角方程。

用法: sympy.expand_trig(expn)
返回:Return the expanded trigonometric expression.

範例1:
在這個例子中,我們可以通過使用sympy.expand_trig(expn)方法,我們能夠找到三角函數的擴展形式。


# Import sympy 
from sympy import *
  
# Define symbols and trigo expression 
x, y = symbols('x y') 
expn = sin(2 * x) + cos(2 * x) 
  
# Use sympy.expand_trig(expn) method 
gfg = expand_trig(expn) 
  
print(gfg)

輸出:

2*sin(x)*cos(x) + 2*cos(x)**2 - 1

範例2:

# Import sympy 
from sympy import *
  
# Define symbols and trigo expression 
x, y = symbols('x y') 
expn = sin(2 * x)**2 + cos(2 * x)**2
  
# Use sympy.expand_trig(expn) method 
gfg = expand_trig(expn) 
  
print(gfg)

輸出:

(2*cos(x)**2 - 1)**2 + 4*sin(x)**2*cos(x)**2



相關用法


注:本文由純淨天空篩選整理自Jitender_1998大神的英文原創作品 Python | sympy.expand_trig() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。