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
40b967d450cc73a5ec8d086a42cb7ff3
mooc-rr
Commits
63ef02b6
Commit
63ef02b6
authored
Nov 02, 2021
by
40b967d450cc73a5ec8d086a42cb7ff3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toy_document_orgmode_R_fr.org: Update
parent
96a967f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
4 deletions
+59
-4
toy_document_orgmode_R_fr.org
module2/exo1/toy_document_orgmode_R_fr.org
+59
-4
No files found.
module2/exo1/toy_document_orgmode_R_fr.org
View file @
63ef02b6
#+TITLE:
Votre titre
#+AUTHOR:
Votre nom
#+DATE:
La date du jour
#+TITLE:
À propos du calcul de \pi
#+AUTHOR:
Arnaud Legrand
#+DATE:
[21:51:00; 19.09.2018]
#+LANGUAGE: fr
# #+PROPERTY: header-args :eval never-export
...
...
@@ -11,7 +11,62 @@
#+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>
* Quelques explications
* En demandant à la lib maths
Mon ordinateur m'indique que \pi vaut /approximativement/
#+begin_src R :results output :session *R* :exports both
pi
#+end_src
#+RESULTS:
: [1] 3.141593
* En utilisant la méthode des aiguilles de Buffon
Mais calculé avec la *méthode* des [[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait comme *approximation* :
#+begin_src R :results output :session *R* :exports both
set.seed(42)
N = 100000
x = runif(N)
theta = pi/2*runif(N)
2/(mean(x+sin(theta)>1))
#+end_src
#+RESULTS:
:
: [1] 3.14327
* Avec un argument "fréquentiel" de surface
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 ~ U(0,1) et Y ~ U(0,1) alors P[X² + Y² <= 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 de Monte Carlo sur Wikipédia]]). 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*
set.seed(42)
N = 1000
df = data.frame(X = runif(N), Y = runif(N))
df$Accept = (df$X**2 + df$Y**2 <=1)
library(ggplot2)
ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw()
#+end_src
#+RESULTS:
[[file:/tmp/babel-mEAAPj/figureTP5NNK.png]]
Il est alors aisé d'obtenir une approximation (pas terrible) de \pi en
comptant combien de fois, en moyenne, X² + Y² est inférieur à 1 :
#+begin_src R :results output :session *R* :exports both
4*mean(df$Accept)
#+end_src
#+RESULTS:
: [1] 3.156
* Quelques explications :noexport:
Ceci est un document org-mode avec quelques exemples de code
R. Une fois ouvert dans emacs, ce document peut aisément être
...
...
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