Skip to content

Commit f8ddc26

Browse files
committed
added documentation for integrate()
1 parent 367899f commit f8ddc26

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/integration.jl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1+
"""
2+
function integrate(
3+
::Type{ValueType},
4+
f,
5+
a::Vector{ValueType},
6+
b::Vector{ValueType};
7+
tolerance=1e-8,
8+
GKorder::Int=15
9+
) where {ValueType}
10+
11+
Integrate the function `f` using TCI and Gauss--Kronrod quadrature rules.
12+
13+
Arguments:
14+
- ValueType: return type of `f`.
15+
- a: Vector of lower bounds in each dimension. Effectively, the lower corner of the hypercube that is being integrated over.
16+
- b: Vector of upper bounds in each dimension.
17+
- tolerance: tolerance of the TCI approximation for the values of f.
18+
- GKorder: Order of the Gauss--Kronrod rule, e.g. 15.
19+
"""
120
function integrate(
221
::Type{ValueType},
322
f,
423
a::Vector{ValueType},
524
b::Vector{ValueType};
625
tolerance=1e-8,
7-
order::Int=15
26+
GKorder::Int=15
827
) where {ValueType}
9-
@assert isodd(order)
10-
@assert length(a) == length(b)
11-
nodes1d, weights1d, _ = QuadGK.kronrod(order ÷ 2, -1, +1)
28+
if iseven(order)
29+
error("Gauss--Kronrod order must be odd, e.g. 15 or 61.")
30+
end
31+
32+
if length(a) != length(b)
33+
error("Integral bounds must have the same dimensionality, but got $(length(a)) lower bounds and $(length(b)) upper bounds.")
34+
end
35+
36+
nodes1d, weights1d, _ = QuadGK.kronrod(GKorder ÷ 2, -1, +1)
1237
nodes = @. (b - a) * (nodes1d' + 1) / 2 + a
1338
weights = @. (b - a) * weights1d' / 2
14-
normalization = order^length(a)
39+
normalization = GKorder^length(a)
1540

1641
localdims = fill(length(nodes1d), length(a))
1742

0 commit comments

Comments
 (0)