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

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
finds the first root of f(x) to the left of 0 .