You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+10-10
Original file line number
Diff line number
Diff line change
@@ -22,18 +22,18 @@ pkg> add MCIntegration
22
22
23
23
To estimate the integral $\int_0^1 \frac{\log(x)}{\sqrt{x}} dx = -4$, you can use:
24
24
```julia
25
-
julia>f(x, c) =log(x[1]) /sqrt(x[1]) # Define your integrand
25
+
julia>f(x, c) =log(x[1]) /sqrt(x[1]);# Define your integrand
26
26
julia>integrate(f, var =Continuous(0, 1), neval=1e5) # Perform the MC integration for 1e5 steps
27
-
Integral 1=-3.99689518016736±0.001364833686666744 (reduced chi2 =0.695)
27
+
Integral 1=-4.000214460546475±0.00030013116779460897 (reduced chi2 =1.29)
28
28
```
29
29
In this example, we define an integrand function `f(x, c)` where `x` represents the random variables in the integral and `c` is a [`Configuration`](https://numericaleft.github.io/MCIntegration.jl/dev/lib/montecarlo/) object that can hold extra parameters that might be necessary for more complex integrand functions. The `var` parameter of `integrate()` specifies the distributions of the variables `x`. Here we set `var = Continuous(0, 1)`, meaning that `x[1]` will be distributed continuously and uniformly on the interval $[0, 1)$. Learn more details from the [documentation](https://numericaleft.github.io/MCIntegration.jl/dev/lib/montecarlo/).
30
30
31
31
`MCIntegration.jl` also supports Discrete variables. For instance, let's estimate $\pi$ through the Taylor series for $\pi/4 = 1 - 1/3 + 1/5 -1/7 + 1/9 - ...$:
32
32
```julia
33
33
34
-
julia>term(n, c) =4* ((-1)^(n[1]+1)) / (2*n[1] -1) # Define your term function where 'n' represents the discrete variable in the integral
34
+
julia>term(n, c) =4* ((-1)^(n[1]+1)) / (2*n[1] -1);# Define your term function where 'n' represents the discrete variable in the integral
35
35
julia>integrate(term; var =Discrete(1, 100), neval =1e5) # Perform the MC integration for 1e5 steps where 'var' is used to specify the type and range of the discrete variable 'n'
36
-
Integral 1=3.120372107250909±0.016964643375124093 (reduced chi2 =1.38)
36
+
Integral 1=3.1544879154329437±0.019339973171423743 (reduced chi2 =0.926)
37
37
```
38
38
39
39
## Understanding Variables
@@ -55,23 +55,23 @@ Here are examples to illustrate the usage of different types of variable vectors
0 commit comments