mirror of
https://app-learninglab.inria.fr/moocrr/gitlab/da84ababf0696af51bddad556af86353/mooc-rr.git
synced 2026-06-17 09:35:24 +02:00
Modification exo1 Module 2 R
This commit is contained in:
parent
7bfce02e67
commit
8040791174
2 changed files with 15 additions and 7 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
|
@ -2,8 +2,6 @@
|
||||||
#+AUTHOR: Louis Lacoste
|
#+AUTHOR: Louis Lacoste
|
||||||
#+DATE: 2022-11-17
|
#+DATE: 2022-11-17
|
||||||
#+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"/>
|
||||||
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
#+HTML_HEAD: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||||
|
|
@ -11,7 +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>
|
||||||
|
|
||||||
* 1 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
|
||||||
pi
|
pi
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
#+RESULTS:
|
#+RESULTS:
|
||||||
: [1] 3.141593
|
: [1] 3.141593
|
||||||
|
|
||||||
* 2 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 [[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait
|
Mais calculé avec la *méthode* des [[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait
|
||||||
comme *approximation* :
|
comme *approximation* :
|
||||||
#+begin_src R :results output :session *R* :exports both
|
#+begin_src R :results output :session *R* :exports both
|
||||||
|
|
@ -30,10 +30,10 @@
|
||||||
theta = pi/2*runif(N)
|
theta = pi/2*runif(N)
|
||||||
2/(mean(x+sin(theta)>1)
|
2/(mean(x+sin(theta)>1)
|
||||||
#+end_src
|
#+end_src
|
||||||
* 3 Avec un argumennt "fréquentiel" de surface
|
* Avec un argumennt "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
|
intervenir d'appel à la fonction sinus se base sur le fait que si
|
||||||
X \sim U(0,1) et Y \sim U(0,1) alors P[X^{2} + Y^{2} \leq 1] = \pi/4 (voir
|
$X \sim U(0,1) et Y \sim U(0,1)$ alors $P[X^{2} + Y^{2} \leq 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 Wikipedia]]). Le code suivant illustre ce
|
[[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 :
|
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 (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R*
|
||||||
|
|
@ -41,4 +41,12 @@ 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))
|
||||||
df$Accept = (df$X**2 + df$Y**2 <= 1)
|
df$Accept = (df$X**2 + df$Y**2 <= 1)
|
||||||
library
|
library(ggplot2)
|
||||||
|
ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw()
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Il est alors aisé d'obtenir une approximation (pas terrible) de \pi en
|
||||||
|
comptant combien de fois, en moyenne, $X^2 + Y^2$ est inférieur à 1 :
|
||||||
|
#+begin_src R :results output :session *R* :exports both
|
||||||
|
4*mean(df$Accept)
|
||||||
|
#+end_src
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue