[−][src]Function reikna::integral::integrate
pub fn integrate(f: &Function, a: f64, b: f64) -> f64
Estimate the value of the integral of f
over [a, b]
.
This is a helper function that calls integrate_wp()
using
a p
value calculated depending on the size of [a, b]
. See
the documentation for integrate_wp()
for more information.
The value of p
is calculated by the following formula:
p = round(|b - a|) * precision
Where precision
is the constant DEFAULT_PRECISION
.
Note -- because of the way the precision is calculated, the
computational complexity of this function grows linearly with
the size of the interval. Very large intervals will have very
large precision values, which can slow down computation while not
providing a large improvement to accuracy. For very large intervals,
is is better to use integrate_wp()
directly, so the precision value
can be set to a more reasonable target.
Examples
#[macro_use] extern crate reikna; use reikna::integral::*; let f = func!(|x| x + 4.0); assert_eq!(integrate(&f, 0.0, 0.0), 0.0); assert_eq!(integrate(&f, 0.0, 1.0), 4.5);