Search code examples
pythonequationnonlinear-functions

How to solve an equation that has tanh() in python


I know how to solve an algebraic Equations : x^4-1=0 as below

from sympy import solve, symbols
x = symbols('x')
solve(x**4 - 1, x)

But I got a problem cuz I have tanh() in my equation today like below:

tanh(C1+x*C2) + tanh(C1-x*C2) = C3

Where C1,C2,C3 are pre-specified then how to solve for x?


Solution

  • As I understood from your question you need just something like

    from sympy import solve, symbols, tanh
    c1 = 1
    c2 = 1
    c3 = 1
    x = symbols('x')
    solve(tanh(c1+x*c2)+tanh(c1-x*c2)-c3, x)