pub fn integrate<F: FnMut(f64) -> f64>(
f: F,
a: f64,
b: f64,
tolerance: f64,
) -> OgeomResult<f64>Expand description
Integrate f over [a, b] to an absolute tolerance.
Subdivides where, and only where, the estimate has not settled, so a mostly-smooth integrand costs about what the smooth part costs.
§What it will not do
Each half is given half its parent’s budget, so the budgets sum to the one
asked for and the result is bounded by it. The cost is that an integrand
with an infinite derivative at an endpoint (sqrt(1 - x^2) at x = 1,
which is a circle’s own equation) has a budget shrinking faster than its
error does, and cannot be squeezed arbitrarily. In practice it manages
about 1e-7 on that shape, and lands within 1e-14 when it does; asked for
1e-8 it reports that it could not rather than returning the number it
reached.
This does not affect arc length, which is what the routine is mostly for:
the speed along a curve is |c'(u)|, smooth and positive wherever the
parameterization is regular. A singularity here means a genuinely singular
parameterization, which is worth being told about.
§Errors
OgeomError::Domain if the interval is not finite;
OgeomError::NotDone if some part of it did not
converge within the depth limit. That is reported rather than returned as a
number, because an integral that silently stopped improving is the shape of
answer that gets trusted.