Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Although for other functions, if there is no root in an interval, you get a RuntimeError that has to be accounted for. So, a bit more obtuse example:

var('k x')
eq = x^3-5*x^2+15==0
ranges = [[k,k+1] for k in [-10..10]]

for width in ranges:
    try:
        root = eq.find_root(width[0],width[1])
        print(f"Root between {width[0]} and {width[1]} is {root}")
    except RuntimeError:
        print(f"No root between {width[0]} and {width[1]}")