Skip to content
Related Articles

Related Articles

Improve Article

Python | sympy.expand_trig() method

  • Last Updated : 18 Jun, 2019
Geek Week

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)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :