This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>.
# Buffon's Needle
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the **approximation**
```{r cars}
summary(cars)
```{r}
set.seed(42)
N = 100000
x = runif(N)
theta = pi/2*runif(N)
2/(mean(x+sin(theta)>1))
```
It is also straightforward to include figures. For example:
```{r pressure, echo=FALSE}
plot(pressure)
```
# Using a surface fraction argument
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
A method that is easier to understand and does not make use of the $sin$ function is based on the fact that if $X ~ U(0,1)$ and $Y ~ U(0,1)$, then $P[X^2 + Y^2 <= 1] = π/4$ (see ["Monte Carlo method" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you.
<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc <2.8).
...
...
@@ -350,41 +349,48 @@ display: none;
<h1class="title toc-ignore">Your title</h1>
<h4class="author">Radu Urian</h4>
<h4class="date">2024-01-05</h4>
<h1class="title toc-ignore">On the computation of pi</h1>
<h4class="author">Arnaud Legrand</h4>
<h4class="date">25 juin 2018</h4>
</div>
<divid="some-explanations"class="section level2">
<h2>Some explanations</h2>
<p>This is an R Markdown document that you can easily export to HTML,
PDF, and MS Word formats. For more information on R Markdown, see <ahref="http://rmarkdown.rstudio.com"class="uri">http://rmarkdown.rstudio.com</a>.</p>
<p>When you click on the button <strong>Knit</strong>, the document will
be compiled in order to re-execute the R code and to include the results
into the final document. As we have shown in the video, R code is
inserted as follows:</p>
<preclass="r"><code>summary(cars)</code></pre>
<pre><code>## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00</code></pre>
<p>It is also straightforward to include figures. For example:</p>
<p>A method that is easier to understand and does not make use of the
<spanclass="math inline">\(sin\)</span> function is based on the fact
that if <spanclass="math inline">\(X ~ U(0,1)\)</span> and <spanclass="math inline">\(Y ~ U(0,1)\)</span>, then <spanclass="math inline">\(P[X^2 + Y^2 <= 1] = π/4\)</span> (see <ahref="https://en.wikipedia.org/wiki/Monte_Carlo_method">“Monte Carlo
method” on Wikipedia</a>). The following code uses this approach:</p>