1
1
# Numerically Solving Integrals
2
2
3
- For basic multidimensional quadrature we can construct and solve a ` IntegralProblem ` .
3
+ For basic multidimensional quadrature, we can construct and solve a ` IntegralProblem ` .
4
4
The integral we want to evaluate is:
5
5
``` math
6
6
\int_1^3\int_1^3\int_1^3 \sum_1^3 \sin(u_i) du_1du_2du_3.
15
15
```
16
16
where the first argument of ` IntegralProblem ` is the integrand,
17
17
the second argument is the lower bound, and the third argument is the upper bound.
18
- ` p ` are the parameters of the integrand. In this case there are no parameters,
18
+ ` p ` are the parameters of the integrand. In this case, there are no parameters,
19
19
but still ` f ` must be defined as ` f(x,p) ` and ** not** ` f(x) ` .
20
20
For an example with parameters, see the next tutorial.
21
21
The first argument of ` solve ` is the problem we are solving,
@@ -25,8 +25,8 @@ in this case tolerances how precise the numerical approximation should be.
25
25
26
26
We can also evaluate multiple integrals at once.
27
27
We could create two ` IntegralProblem ` s for this,
28
- but that is wasteful if the integrands share alot of computation.
29
- We also want to evaluate:
28
+ but that is wasteful if the integrands share a lot of computation.
29
+ For example, we also want to evaluate:
30
30
``` math
31
31
\int_1^3\int_1^3\int_1^3 \sum_1^3 \cos(u_i) du_1du_2du_3.
32
32
```
@@ -40,10 +40,10 @@ sol.u
40
40
The keyword ` nout ` now has to be specified equal to the number of integrals ware are calculating, 2.
41
41
Another way to think about this is that the integrand is now a vector valued function.
42
42
The default value for the keyword ` nout ` is 1,
43
- thus is does not need to be specified for scalar valued functions.
44
- In the above example the integrand was defined out-of-position.
43
+ and thus it does not need to be specified for scalar valued functions.
44
+ In the above example, the integrand was defined out-of-position.
45
45
This means that a new output vector is created every time the function ` f ` is called.
46
- If we do not want these allocations we can also define ` f ` in-position.
46
+ If we do not want these allocations, we can also define ` f ` in-position.
47
47
``` @example integrate3
48
48
using Integrals, IntegralsCubature
49
49
function f(y,u,p)
@@ -79,7 +79,7 @@ Both `u` and `y` changed from vectors to matrices,
79
79
where each column is respectively a point the integrand is evaluated at or
80
80
the evaluation of the integrand at the corresponding point.
81
81
Try to create yourself an out-of-position version of the above problem.
82
- For the full details of the batching interface, see the [ problem page] (@ref prob)
82
+ For the full details of the batching interface, see the [ problem page] (@ref prob).
83
83
84
84
If we would like to compare the results against Cuba.jl's ` Cuhre ` method, then
85
85
the change is a one-argument change:
@@ -93,12 +93,12 @@ sol = solve(prob,CubaCuhre();reltol=1e-3,abstol=1e-3)
93
93
sol.u
94
94
```
95
95
However, ` Cuhre ` does not support vector valued integrands.
96
- The [ solvers page] (@ref solvers) gives an overview which arguments each algorithm can handle.
96
+ The [ solvers page] (@ref solvers) gives an overview of which arguments each algorithm can handle.
97
97
98
98
## One-dimensional integrals
99
99
100
100
Integrals.jl also has specific solvers for integrals in a single dimension, such as ` QuadGKLJ ` .
101
- For example we can create our own sine function by integrating the cosine function from 0 to x.
101
+ For example, we can create our own sine function by integrating the cosine function from 0 to x.
102
102
103
103
``` @example integrate6
104
104
using Integrals
@@ -116,13 +116,13 @@ and the integral is thus transformed to:
116
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
117
```
118
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}$,
119
+ If both upper and lower bound are infinite, $u$ is substituted with $\frac{t}{1-t^2}$,
120
120
``` math
121
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
122
```
123
123
For multidimensional integrals, each variable with infinite bounds is substituted the same way.
124
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 ) .
125
+ [ here] ( https://en.wikipedia.org/wiki/Integration_by_substitution#Substitution_for_multiple_variables ) .
126
126
127
127
As an example, let us integrate the standard bivariate normal probability distribution
128
128
over the area above the horizontal axis, which should be equal to $0.5$.
0 commit comments