mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-02-04 11:32:10 +01:00
Refactor files
This commit is contained in:
17
M1/Monte Carlo Methods/Exercise3.rmd
Normal file
17
M1/Monte Carlo Methods/Exercise3.rmd
Normal file
@@ -0,0 +1,17 @@
|
||||
# Exercise 3 : Box Muller Algo
|
||||
|
||||
```{r}
|
||||
BM <- function(n) {
|
||||
U1 <- runif(n)
|
||||
U2 <- runif(n)
|
||||
X1 <- sqrt(-2 * log(U1)) * cos(2 * pi * U2)
|
||||
X2 <- sqrt(-2 * log(U1)) * sin(2 * pi * U2)
|
||||
return(c(X1, X2))
|
||||
}
|
||||
|
||||
n <- 10e4
|
||||
X <- BM(n)
|
||||
|
||||
hist(X, breaks = 100, freq = FALSE)
|
||||
curve(dnorm(x), add = TRUE, col = "red")
|
||||
```
|
||||
Reference in New Issue
Block a user