(f, x)
return x0
Finds the first root of f(x) to the left of 0.

    The x0 and dx below are taylored to get the correct result for our
    particular function --- the general solver often overshoots the first
    solution.
Finds the first root of f(x) to the left of 0.
Finds the first root of f ( x ) to the left of 0 .
def msolve(f, x):
    """
    Finds the first root of f(x) to the left of 0.

    The x0 and dx below are taylored to get the correct result for our
    particular function --- the general solver often overshoots the first
    solution.
    """
    f = lambdify(x, f)
    x0 = -0.001
    dx = 0.001
    while f(x0 - dx) * f(x0) > 0:
        x0 = x0 - dx
    x_max = x0 - dx
    x_min = x0
    assert f(x_max) > 0
    assert f(x_min) < 0
    for n in range(100):
        x0 = (x_max + x_min)/2
        if f(x0) > 0:
            x_max = x0
        else:
            x_min = x0
    return x0
def msolve ( f , x ) : f = lambdify ( x , f ) x0 = - 0.001 dx = 0.001 while f ( x0 - dx ) * f ( x0 ) > 0 : x0 = x0 - dx x_max = x0 - dx x_min = x0 assert f ( x_max ) > 0 assert f ( x_min ) < 0 for n in range ( 100 ) : x0 = ( x_max + x_min ) / 2 if f ( x0 ) > 0 : x_max = x0 else : x_min = x0 return x0