Solve an equation using a python numerical solver in numpy

前端 未结 2 2031
感动是毒
感动是毒 2021-01-30 17:24

I have an equation, as follows:

R - ((1.0 - np.exp(-tau))/(1.0 - np.exp(-a*tau))) = 0.

I want to solve for tau in this equation using a

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 17:34

    You can rewrite the equation as

    eq

    • For integer a and non-zero R you will get a solutions in the complex space;
    • There are analytical solutions for a=0,1,...4(see here);

    So in general you may have one, multiple or no solution and some or all of them may be complex values. You may easily throw scipy.root at this equation, but no numerical method will guarantee to find all the solutions.

    To solve in the complex space:

    import numpy as np
    from scipy.optimize import root
    
    def poly(xs, R, a):
        x = complex(*xs)
        err = R * x - x + 1 - R
        return [err.real, err.imag]
    
    root(poly, x0=[0, 0], args=(1.2, 6))
    

提交回复
热议问题