From 3efc9b2d49a587d80f275a763842b8897a49040d Mon Sep 17 00:00:00 2001 From: c5e26cdef30a6aad273a095700de6ac0 Date: Thu, 30 Nov 2023 13:44:19 +0000 Subject: [PATCH] Update exercice_R_fr.org --- module2/exo3/exercice_R_fr.org | 43 +--------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/module2/exo3/exercice_R_fr.org b/module2/exo3/exercice_R_fr.org index 5dd3e63..eff800b 100644 --- a/module2/exo3/exercice_R_fr.org +++ b/module2/exo3/exercice_R_fr.org @@ -1,52 +1,11 @@ --- -title: "Module 2, exos 2" +title: "Module 2, exos 3" author: "Fanny De Carvalho" date: "30/11/2023" output: html_document --- -# En demandant à la lib maths -Mon ordinateur m'indique que π vaut *approximativement* -```{r} -pi -``` -# En utilisant la méthode des aiguilles de Buffon -Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **approximation**: - -```{r} -set.seed(42) -N = 100000 -x = runif(N) -theta = pi/2*runif(N) -2/(mean(x+sin(theta)>1)) -``` -# Avec un argumant "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[X2+Y2≤1]=π/4 (voir [méthode de Monte Carlo sur Wikipédia](https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80)). Le code suivant illustre ce fait: -```{r, message = FALSE, warning = FALSE} -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() -``` - -Il est alors aisé d’obtenir une approximation (pas terrible) de π en comptant combien de fois, en moyenne, X2 + Y2 est inférieur à 1: -```{r} -4*mean(df$Accept) -``` - -```{r} -data <- c(14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0) - -mean(data) -sd(data) -min(data) -max(data) -median(data) - -``` ```{r} data <- c(14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0) -- 2.18.1