sympy.expand_trig(expression)方法
借助于sympy.expand_trig()方法,我们可以将任何三角表达式展开到它的最低形式。
语法:expand_trig(expression)
参数: expression – 它是将展开的三角函数表达式
返回值: 返回展开后的三角表达式。
sympy.expand_trig(expression)方法 例# 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))
Output:
Before Trigonometric Expansion : sin(2*x) + cos(2*x)
After Trigonometric Expansion : 2*sin(x)*cos(x) + 2*cos(x)**2 - 1
sympy.expand_trig(expression)方法 例# 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))
Output:
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)