optimization - Python: alternate to brentq and fsolve in python that finds all the zeros of the given function -
is there module find zeros of function instead of first 0 encounters beyond specified starting point?
with brentq
, specify function changes sign , pick location unless did n
times. similarly, fsolve
, pick starting point , finds first 0 beyond point , again have n
times. how find n
locations in 1 calling n < infinity
of course.
the function have in mind 3 zeros , below:
import numpy np import pylab scipy.optimize import brentq mm = 7.3477e22 # mass moon me = 5.9736e24 # mass earth r12 = 384400.0 # distance between earth , moon pi2 = mm / (me + mm) def f(xi): return ((1.0 - pi2) / np.absolute(xi - pi2) ** 3.0 * (xi + pi2) + pi2 / np.absolute(xi + pi2 - 1.0) ** 3.0 * (xi + pi2 - 1.0) - xi)
Comments
Post a Comment