Skip to content

Commit adf512a

Browse files
Merge pull request #130 from ArnoStrouwen/tutinf
Infinity tutorial
2 parents aad1e72 + 67ee031 commit adf512a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
45
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

docs/src/tutorials/numerical_integrals.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ sol.u
9595
However, `Cuhre` does not support vector valued integrands.
9696
The [solvers page](@ref solvers) gives an overview which arguments each algorithm can handle.
9797

98+
## One-dimensional integrals
99+
98100
Integrals.jl also has specific solvers for integrals in a single dimension, such as `QuadGKLJ`.
99101
For example we can create our own sine function by integrating the cosine function from 0 to x.
100102

@@ -103,4 +105,34 @@ using Integrals
103105
my_sin(x) = solve(IntegralProblem((x,p)->cos(x), 0.0, x), QuadGKJL()).u
104106
x = 0:0.1:2*pi
105107
@. my_sin(x) ≈ sin(x)
108+
```
109+
110+
## Infinity handling
111+
112+
Integrals.jl can also handle infinite integration bounds.
113+
For infinite upper bounds $u$ is substituted with $a+\frac{t}{1-t}$,
114+
and the integral is thus transformed to:
115+
```math
116+
\int_a^\infty f(u)du = \int_0^1 f\left(a+\frac{t}{1-t}\right)\frac{1}{(1-t)^2}dt
117+
```
118+
Integrals with an infinite lower bound are handled in the same way.
119+
If both upper and lower bound are infinite $u$ is substituted with $\frac{t}{1-t^2}$,
120+
```math
121+
\int_{-\infty}^\infty f(u)du = \int_{-1}^1 f\left(\frac{t}{1-t^2}\right)\frac{1+t^2}{(1-t^2)^2}dt
122+
```
123+
For multidimensional integrals, each variable with infinite bounds is substituted the same way.
124+
The details of the math behind these transforms can be found
125+
[here.](https://en.wikipedia.org/wiki/Integration_by_substitution#Substitution_for_multiple_variables).
126+
127+
As an example, let us integrate the standard bivariate normal probability distribution
128+
over the area above the horizontal axis, which should be equal to $0.5$.
129+
130+
``` @example integrate6
131+
using Distributions
132+
using Integrals
133+
dist = MvNormal(ones(2))
134+
f = (x,p)->pdf(dist,x)
135+
(lb, ub) = ([-Inf,0.0], [Inf,Inf])
136+
prob = IntegralProblem(f, lb, ub)
137+
solve(prob,HCubatureJL(), reltol = 1e-3, abstol = 1e-3)
106138
```

0 commit comments

Comments
 (0)