mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-02-13 10:07:36 +01:00
Add exercise 10
This commit is contained in:
48
M1/Monte Carlo Methods/Exercise10.rmd
Normal file
48
M1/Monte Carlo Methods/Exercise10.rmd
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Exercise 10 : Integral Calculation.
|
||||||
|
|
||||||
|
## Estimation of δ using the classical Monte Carlo
|
||||||
|
|
||||||
|
### Uniform + Normal distributions
|
||||||
|
|
||||||
|
```{r}
|
||||||
|
n <- 10e4
|
||||||
|
X <- runif(n, 0, 5)
|
||||||
|
Y <- rnorm(n, 0, sqrt(2))
|
||||||
|
Y[Y <= 2] <- 0
|
||||||
|
|
||||||
|
h <- function(x, y) {
|
||||||
|
10 *
|
||||||
|
sqrt(pi) *
|
||||||
|
sqrt(x + y) *
|
||||||
|
sin(y^4) *
|
||||||
|
exp(-3 * x / 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
I1 <- mean(h(X, Y))
|
||||||
|
I1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exponential + Normal distributions
|
||||||
|
|
||||||
|
```{r}
|
||||||
|
n <- 10e4
|
||||||
|
X <- runif(n, 0, 5)
|
||||||
|
Y <- rexp(n, 3 / 2)
|
||||||
|
Y[Y <= 2] <- 0
|
||||||
|
X[X <= 5] <- 0
|
||||||
|
|
||||||
|
h <- function(x, y) {
|
||||||
|
4 / 3 * sqrt(pi) * sqrt(x + y) * sin(y^4)
|
||||||
|
}
|
||||||
|
|
||||||
|
I2 <- mean(h(X, Y))
|
||||||
|
I2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exponential + Truncated Normal distributions
|
||||||
|
|
||||||
|
```{r}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Computational cost of these methods.
|
||||||
Reference in New Issue
Block a user