Search code examples
pythonnumpymathnatural-logarithm

Natural Logarithm algebra in numpy


I have the following equation:

import numpy as np

d = (x - y) / np.log((x - z) / (y - z))

Where I am trying to find x

Is this possible in numpy or other python libraries? In this case, could you please provide sample code of how to do it with this specific problem?


Solution

  • I would probably use just sympy and their solver: sympy Library Solver

    from sympy import solve, log, exp
    from sympy.abc import x,y,z,d
    
    f = (x - y) / log((x - z) / (y - z)) - d
    
    solution = solve(f, x)
    

    And the output is giving me is

    [-d*LambertW(-(y - z)*exp(-(y - z)/d)/d) + z]