Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
f6f8a22e4377b6d0231cab92d0d5018b
mooc-rr
Commits
56707eea
Commit
56707eea
authored
Apr 24, 2020
by
Olivia Guillin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deuxième_essai
parent
f891b4e8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
10 deletions
+8
-10
toy_document_orgmode_R_fr.org
module2/exo1/toy_document_orgmode_R_fr.org
+8
-10
No files found.
module2/exo1/toy_document_orgmode_R_fr.org
View file @
56707eea
#+TITLE: À propos du calcul de $\pi$
#+TITLE: À propos du calcul de $\pi$
#+LANGUAGE: fr
#+LANGUAGE: fr
# #+PROPERTY: header-args :eval never-export
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
...
@@ -10,8 +9,9 @@
...
@@ -10,8 +9,9 @@
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
* En demandant à la lib maths
# #+PROPERTY: header-args :session :exports both
* En demandant à la lib maths
Mon ordinateur m'indique que $\pi$ vaut /approximativement/
Mon ordinateur m'indique que $\pi$ vaut /approximativement/
#+begin_src R :results output :session *R* :exports both
#+begin_src R :results output :session *R* :exports both
...
@@ -22,8 +22,7 @@ pi
...
@@ -22,8 +22,7 @@ pi
: [1] 3.141593
: [1] 3.141593
* En utilisant la méthode des aiguilles de Buffon
* En utilisant la méthode des aiguilles de Buffon
Mais calculé avec la *méthode* des
Mais calculée avec la *méthode* des
[[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait comme *approximation* :
[[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait comme *approximation* :
#+begin_src R :results output :session *R* :exports both
#+begin_src R :results output :session *R* :exports both
...
@@ -35,18 +34,17 @@ theta = pi/2*runif(N)
...
@@ -35,18 +34,17 @@ theta = pi/2*runif(N)
#+end_src
#+end_src
#+RESULTS:
#+RESULTS:
:
: [1] 3.14327
: [1] 3.14327
* Avec un argument "fréquentiel" de surface
* Avec un argument "fréquentiel" de surface
Sinon, une méthode plus simple à comprendre et ne faisant pas
Sinon, une méthode plus simple à comprendre et ne faisant pas
intervenir d'appel à la fonction sinus se base sur le fait que si
$X \sim
intervenir d'appel à la fonction sinus se base sur le fait que si
U(0,1)$ et $Y \sim U(0,1)$ alors $P[X^2 + Y^2 \le
1] = \pi/4$ (voir
$X\sim U(0,1)$ et $Y\sim U(0,1)$ alors $P[X^2+Y^2 \le
1] = \pi/4$ (voir
[[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80][méthode
[[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80][méthode
de Monte Carlo sur Wikipedia]]). Le code suivant illustre ce fait :
de Monte Carlo sur Wikipedia]]). Le code suivant illustre ce fait :
#+begin_src R :results output graphics :file
(org-babel-temp-file "figure" ".png"
) :exports both :width 600 :height 400 :session *R*
#+begin_src R :results output graphics :file
figure_pi_mc1.png
) :exports both :width 600 :height 400 :session *R*
set.seed(42)
set.seed(42)
N = 1000
N = 1000
df = data.frame(X = runif(N), Y = runif(N))
df = data.frame(X = runif(N), Y = runif(N))
...
@@ -56,11 +54,11 @@ ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + t
...
@@ -56,11 +54,11 @@ ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + t
#+end_src
#+end_src
#+RESULTS:
#+RESULTS:
[[file:
/var/folders/21/wtvjlyxj21b3gj703l4k0j_40000gp/T/babel-Dmfygk/figure9U9fXz.png
]]
[[file:
figure_pi_mc1.png)
]]
Il est alors aisé d'obtenir une approximation (pas terrible) de $\pi$ en
Il est alors aisé d'obtenir une approximation (pas terrible) de $\pi$ en
comptant combien de fois, $X^2 + Y^2$ est inférieur à 1 :
comptant combien de fois,
en moyenne,
$X^2 + Y^2$ est inférieur à 1 :
#+begin_src R :results output :session *R* :exports both
#+begin_src R :results output :session *R* :exports both
4*mean(df$Accept)
4*mean(df$Accept)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment