Commit 99c98cb5 authored by David Elser's avatar David Elser

final

parent cb7988d1
--- ---
title: "On the computation of pi" title: "On the computation of pi"
author: "*Arnaud Legrand*" author: "Arnaud Legrand"
date: "*25 juin 2018*" date: "25 juin 2018"
output: html_document output: html_document
--- ---
...@@ -9,7 +9,7 @@ output: html_document ...@@ -9,7 +9,7 @@ output: html_document
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
``` ```
# Asking the maths libary ## Asking the maths library
My computer tells me that $\pi$ is *approximatively* My computer tells me that $\pi$ is *approximatively*
```{r} ```{r}
...@@ -17,7 +17,7 @@ pi ...@@ -17,7 +17,7 @@ pi
``` ```
## Buffon's needle ## Buffon's needle
Applying the methond of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the __approximation__) Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the __approximation__)
```{r} ```{r}
set.seed(42) set.seed(42)
...@@ -27,7 +27,7 @@ theta = pi/2*runif(N) ...@@ -27,7 +27,7 @@ theta = pi/2*runif(N)
2/(mean(x+sin(theta)>1)) 2/(mean(x+sin(theta)>1))
``` ```
## Using a surface fraction arugment ## 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[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: 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} ```{r}
......
...@@ -375,20 +375,21 @@ $(document).ready(function () { ...@@ -375,20 +375,21 @@ $(document).ready(function () {
<h1 class="title toc-ignore">On the computation of pi</h1> <h1 class="title toc-ignore">On the computation of pi</h1>
<h4 class="author"><em>Arnaud Legrand</em></h4> <h4 class="author">Arnaud Legrand</h4>
<h4 class="date"><em>25 juin 2018</em></h4> <h4 class="date">25 juin 2018</h4>
</div> </div>
<div id="asking-the-maths-libary" class="section level1"> <div id="asking-the-maths-library" class="section level2">
<h1>Asking the maths libary</h1> <h2>Asking the maths library</h2>
<p>My computer tells me that <span class="math inline">\(\pi\)</span> is <em>approximatively</em></p> <p>My computer tells me that <span class="math inline">\(\pi\)</span> is <em>approximatively</em></p>
<pre class="r"><code>pi</code></pre> <pre class="r"><code>pi</code></pre>
<pre><code>## [1] 3.141593</code></pre> <pre><code>## [1] 3.141593</code></pre>
</div>
<div id="buffons-needle" class="section level2"> <div id="buffons-needle" class="section level2">
<h2>Buffon’s needle</h2> <h2>Buffon’s needle</h2>
<p>Applying the methond of <a href="https://en.wikipedia.org/wiki/Buffon%27s_needle_problem">Buffon’s needle</a>, we get the <strong>approximation</strong>)</p> <p>Applying the method of <a href="https://en.wikipedia.org/wiki/Buffon%27s_needle_problem">Buffon’s needle</a>, we get the <strong>approximation</strong>)</p>
<pre class="r"><code>set.seed(42) <pre class="r"><code>set.seed(42)
N = 100000 N = 100000
x = runif(N) x = runif(N)
...@@ -396,8 +397,8 @@ theta = pi/2*runif(N) ...@@ -396,8 +397,8 @@ theta = pi/2*runif(N)
2/(mean(x+sin(theta)&gt;1))</code></pre> 2/(mean(x+sin(theta)&gt;1))</code></pre>
<pre><code>## [1] 3.14327</code></pre> <pre><code>## [1] 3.14327</code></pre>
</div> </div>
<div id="using-a-surface-fraction-arugment" class="section level2"> <div id="using-a-surface-fraction-argument" class="section level2">
<h2>Using a surface fraction arugment</h2> <h2>Using a surface fraction argument</h2>
<p>A method that is easier to understand and does not make use of the <span class="math inline">\(\sin\)</span> function is based on the fact that if <span class="math inline">\(X\sim U(0,1)\)</span> and <span class="math inline">\(Y\sim U(0,1)\)</span>, then <span class="math inline">\(P[X^2+Y^2\leq 1] = \pi/4\)</span> (see <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">“Monte Carlo method” on Wikipedia</a>). The following code uses this approach:</p> <p>A method that is easier to understand and does not make use of the <span class="math inline">\(\sin\)</span> function is based on the fact that if <span class="math inline">\(X\sim U(0,1)\)</span> and <span class="math inline">\(Y\sim U(0,1)\)</span>, then <span class="math inline">\(P[X^2+Y^2\leq 1] = \pi/4\)</span> (see <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">“Monte Carlo method” on Wikipedia</a>). The following code uses this approach:</p>
<pre class="r"><code>set.seed(42) <pre class="r"><code>set.seed(42)
N = 1000 N = 1000
...@@ -415,7 +416,6 @@ library(ggplot2)</code></pre> ...@@ -415,7 +416,6 @@ library(ggplot2)</code></pre>
<pre class="r"><code>4*mean(df$Accept)</code></pre> <pre class="r"><code>4*mean(df$Accept)</code></pre>
<pre><code>## [1] 3.156</code></pre> <pre><code>## [1] 3.156</code></pre>
</div> </div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment