mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 18:59:59 +01:00
17 lines
309 B
Plaintext
17 lines
309 B
Plaintext
# 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 = 50, freq = FALSE)
|
|
curve(dnorm(x), add = TRUE, col = "red")
|
|
``` |