Python| sympy.trigsimp() 方法
借助sympy.trigsimp()方法,我们可以使用三角恒等式简化数学表达式。
Syntax: trigsimp(expression)
Parameters:
expression – It is the mathematical expression which needs to be simplified.
Returns: Returns a simplified mathematical expression corresponding to the input expression.
示例 #1:
在这个例子中,我们可以看到通过使用sympy.trigsimp()方法,我们可以简化任何数学表达式。
# import sympy
from sympy import *
x = symbols('x')
expr = sin(x)**2 + cos(x)**2
print("Before Simplification : {}".format(expr))
# Use sympy.trigsimp() method
smpl = trigsimp(expr)
print("After Simplification : {}".format(smpl))
输出:
Before Simplification : sin(x)**2 + cos(x)**2
After Simplification : 1
示例 #2:
# import sympy
from sympy import *
x = symbols('x')
expr = sin(x)**4 - 2 * cos(x)**2 * sin(x)**2 + cos(x)**4
print("Before Simplification : {}".format(expr))
# Use sympy.trigsimp() method
smpl = trigsimp(expr)
print("After Simplification : {}".format(smpl))
输出:
Before Simplification : sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4
After Simplification : cos(4*x)/2 + 1/2