verry.optimize.allroot_scalar#
- verry.optimize.allroot_scalar(fun, domain, fprime=None, unique=False, max_iter=16)#
Find all roots of univariate scalar-valued function.
- Parameters:
fun (Callable) – Function to find a root of.
domain (Interval) – Interval for which roots are searched.
fprime (Callable, optional) – Derivative of fun (the default is
deriv(fun)
).unique (bool, default=False) – If unique is
True
, verification continues until the number of iterations reaches max_iter or the uniqueness of the root is verified, even if its existence has been established.max_iter (int, default=16) – Maximum number of iterations.
- Return type:
Warning
fun must be a \(C^1\)-function on domain. Futhermore, fun must neither be a constant nor contain conditional branches (cf. Common pitfalls).
See also
Examples
>>> from verry import FloatInterval as FI >>> from verry import function as vrf >>> r = allroot_scalar(lambda x: x**3 - 2 * x, FI(-2, 3), unique=True) >>> len(r.unique) 3 >>> root_max = max(r.unique, key=lambda x: x.sup) >>> root_max.issuperset(vrf.sqrt(FI(2))) True