Search code examples
pythonmathtrigonometry

Is it possible to solve trignomatic problems using python?


I was thinking to create a app which simply the trignomatic problems using python with math lib, Is it possible to solve them without providing the value of angle?

Example: Input: (cosx + sinx)/(cosx - sinx) Output: (1 + tanx)/(1-tanx)

It will me a lot.


Solution

  • Yes, there is. You could use the sympy package. A possible implementation of your question would be:

    from sympy import symbols, cos, sin, tan, simplify, trigsimp
    
    # Define the variable
    x = symbols('x')
    
    # Define the expression
    expr = (cos(x) + sin(x)) / (cos(x) - sin(x))
    
    # Simplify the expression
    simplified_expr = trigsimp(expr)
    
    print(simplified_expr)
    

    This outputs tan(x + pi/4), which is equal to your solution.