Saturday, December 28, 2024
Google search engine
HomeLanguagesPython | sympy.trigsimp() method

Python | sympy.trigsimp() method

With the help of sympy.trigsimp() method, we can simplify mathematical expressions using trigonometric identities.

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.

Example #1: In this example, we can see that by using sympy.trigsimp() method, we can simplify any mathematical expression. 

Python3




# 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))
 
# This trigonometric expansion also be done using by simplify method
 
expr1 = sin(x)**2 + cos(x)**2
 
print("Using simplify method : {}" .format(simplify(expr1)))


Output:

Before Simplification : sin(x)**2 + cos(x)**2
After Simplification : 1
Using simplify method : 1

Example #2: 

Python3




# 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))
 
# This trigonometric expansion also be done using by simplify method
 
expr1 = sin(x)**4 - 2 * cos(x)**2 * sin(x)**2 + cos(x)**4
 
print("Using simplify method : {}" .format(simplify(expr1)))


Output:

Before Simplification : sin(x)**4 - 2*cos(x)**2*sin(x)**2 + cos(x)**4
After Simplification : cos(4*x)/2 + 1/2
Using simplify method : cos(4*x)/2 + 1/2

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments