📜  Python| sympy.expand_trig() 方法

📅  最后修改于: 2022-05-13 01:54:48.452000             🧑  作者: Mango

Python| sympy.expand_trig() 方法

sympy.expand_trig()方法的帮助下,我们可以将任何三角表达式展开到它的最低形式。

示例 #1:

在这个例子中,我们可以看到通过使用sympy.expand_trig()方法,我们可以展开任何三角表达式。

# import sympy
from sympy import * 
  
x = symbols('x')
exp = sin(2 * x) + cos(2 * x)
print("Before Trigonometric Expansion : {}".format(exp)) 
    
# Use sympy.expand_trig() method
res_exp = expand_trig(exp) 
    
print("After Trigonometric Expansion : {}".format(res_exp)) 

输出:

Before Trigonometric Expansion : sin(2*x) + cos(2*x)
After Trigonometric Expansion : 2*sin(x)*cos(x) + 2*cos(x)**2 - 1

示例 #2:

# import sympy
from sympy import * 
  
x, y = symbols('x y')
exp = cos(3 * x) - sin(3 * y)
print("Before Trigonometric Expansion : {}".format(exp)) 
    
# Use sympy.expand_trig() method
res_exp = expand_trig(exp) 
    
print("After Trigonometric Expansion : {}".format(res_exp)) 

输出:

Before Trigonometric Expansion : -sin(3*y) + cos(3*x)
After Trigonometric Expansion : 4*sin(y)**3 - 3*sin(y) + 4*cos(x)**3 - 3*cos(x)