1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use crate;
use crateIntegralEstimate;
use crateIntegrand;
use crateLimits;
/// A non-adaptive Gauss-Kronrod integrator.
///
/// The [`Basic`] integrator applies a Gauss-Kronrod integration [`Rule`] to approximate the
/// integral of a one-dimensional function. It is non-adaptive: it runs exactly once on the input
/// function. Thus, it is only suitable for the integration of smooth functions with no problematic
/// regions in the integration region. If higher accuracy is required then the [`Adaptive`] or
/// [`AdaptiveSingularity`] integrators should be used instead.
///
/// [`Adaptive`]: crate::quadrature::Adaptive
/// [`AdaptiveSingularity`]: crate::quadrature::AdaptiveSingularity
///
/// # Example
///
/// Here we present a calculation of the golden ratio $\varphi$ ([`std::f64::consts::GOLDEN_RATIO`])
/// using the integral representation,
/// $$
/// \ln \varphi = \int_{0}^{1/2} \frac{dx}{\sqrt{1 + x^{2}}}
/// $$
///```rust
/// use rint::{Integrand, Limits};
/// use rint::quadrature::{Basic, Rule};
///
/// const PHI: f64 = std::f64::consts::GOLDEN_RATIO;
///
/// struct GoldenRatio;
///
/// impl Integrand for GoldenRatio {
/// type Point = f64;
/// type Scalar = f64;
///
/// fn evaluate(&self, x: &Self::Point) -> Self::Scalar {
/// 1.0 / (1.0 + x.powi(2)).sqrt()
/// }
/// }
///
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let golden_ratio = GoldenRatio;
/// let limits = Limits::new(0.0,0.5)?;
/// let rule = Rule::gk15();
/// let integral = Basic::new(&golden_ratio, &rule, limits)
/// .integrate();
///
/// let result = integral.result();
/// let error = integral.error();
/// let abs_actual_error = (PHI.ln() - result).abs();
/// let iters = integral.iterations();
/// assert_eq!(iters, 1);
/// assert!(abs_actual_error < error);
/// # Ok(())
/// # }
///```