Open In App

Python | sympy.expand_trig() method

Last Updated : 18 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of sympy.expand_trig() method, we can expand any trigonometric expression to its lowest form.

Syntax: expand_trig(expression)

Parameters:
expression – It is the trigonometric expression which will be expanded.

Returns: Returns the trigonometric expression after its expansion.

Example #1:

In this example we can see that by using sympy.expand_trig() method, we can expand any trigonometric expression.




# 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

Example #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)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads