1 | initial version |
I don't think that there's anything in Sage, but you can use something like the following function:
def find_all_roots(f, a, b, eps=0.0000000001):
roots = []
intervals_to_check = [(a,b)]
while intervals_to_check:
start, end = intervals_to_check.pop()
try:
root = find_root(f, start, end)
except RuntimeError:
continue
if root in roots:
continue
if abs(f(root)) < 1:
roots.append(root)
intervals_to_check.extend([(start, root-eps), (root+eps, end)])
roots.sort()
return roots
It then behaves like the following:
sage: f = tan(z)+z/sqrt(9*pi^2-z^2)
sage: find_all_roots(f, 0, 9.4)
[0.0, 2.8359523267114892, 5.6414610103726988, 8.3387745764121703]
Note that I had to change the endpoint since find_root
does not like it when the function is not defined.