From 87c91ec455de8c98bc84c540b926cb44f62e601b Mon Sep 17 00:00:00 2001 From: amarell Date: Fri, 9 Jun 2023 17:02:42 +0200 Subject: [PATCH] Additional minor corrections to module2/exo1/toy_document_en.Rmd --- module2/exo1/toy_document_en.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module2/exo1/toy_document_en.Rmd b/module2/exo1/toy_document_en.Rmd index 383c97f..04ab5f5 100644 --- a/module2/exo1/toy_document_en.Rmd +++ b/module2/exo1/toy_document_en.Rmd @@ -28,7 +28,7 @@ theta = pi/2*runif(N) ``` ## Using a surface fraction argument -A method that is easier to understand and does not make use of the $sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim U(0,1)$, then $P[X2+Y2\leq 1]= \pi/4$ (see ["Monte Carlo method" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach: +A method that is easier to understand and does not make use of the $\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim U(0,1)$, then $P[X^2+Y^2\leq 1] = \pi/4$ (see ["Monte Carlo method" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach: ```{r} set.seed(42) @@ -39,7 +39,7 @@ library(ggplot2) ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw() ``` -It is then straightforward to obtain a (not really good) approximation to $\pi$ by counting how many times, on average, $X^2 + Y^2$ is smaller than 1 : +It is then straightforward to obtain a (not really good) approximation to $\pi$ by counting how many times, on average, $X^2 + Y^2$ is smaller than 1: ```{r} 4*mean(df$Accept) -- 2.18.1