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
bcd5f406b2a667e8cf7612a7644cd3f8
mooc-rr
Commits
3c08d49c
You need to sign in or sign up before continuing.
Commit
3c08d49c
authored
Sep 19, 2023
by
bcd5f406b2a667e8cf7612a7644cd3f8
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fichier en HTML, Markdown, figure et jupyter
parent
4d6905b2
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13422 additions
and
0 deletions
+13422
-0
Exercice Mod 2 Exe 1 en jupyter.pdf
module2/exo1/Exercice Mod 2 Exe 1 en jupyter.pdf
+0
-0
Mon_toy_notebook_fr.html
module2/exo1/Mon_toy_notebook_fr.html
+13335
-0
Mon_toy_notebook_fr.md
module2/exo1/Mon_toy_notebook_fr.md
+87
-0
output_12_0.png
module2/exo1/output_12_0.png
+0
-0
No files found.
module2/exo1/Exercice Mod 2 Exe 1 en jupyter.pdf
0 → 100644
View file @
3c08d49c
File added
module2/exo1/Mon_toy_notebook_fr.html
0 → 100644
View file @
3c08d49c
This diff is collapsed.
Click to expand it.
module2/exo1/Mon_toy_notebook_fr.md
0 → 100644
View file @
3c08d49c
<div
align=
"center"
>
Mon_toy_notebook_fr
</div>
<div
align=
"center"
>
Martha HENRI
</div>
<div
align=
"center"
>
19/09/2023
</div>
## 1 A propos du calcul de $\pi$
## 1.1 En demandant à la lib maths
Mon ordinateur m'indique que $
\p
i$ vaut
*aproximativement*
```python
from math import *
print(pi)
```
3.141592653589793
## 1.2 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 __aproximation__ :
```python
import numpy as np
np.random.seed(seed=42)
N = 10000
x = np.random.uniform(size=N, low=0, high=1)
theta = np.random.uniform(size=N, low=0, high=pi/2)
2/(sum((x+np.sin(theta))>1)/N)
```
3.128911138923655
## 1.3 Avec un argument "frequentiel" 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<sup>2</sup> + Y<sup>2</sup> <= 1
]
= $
\p
i$/4 (voir
[
méthode de Monte Carlo sur Wikipedia
](
https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo
)
). Le code suivant illustre ce fait :
```python
%matplotlib inline
import matplotlib.pyplot as plt
np.random.seed(seed=42)
N = 1000
x = np.random.uniform(size=N, low=0, high=1)
y = np.random.uniform(size=N, low=0, high=1)
accept = (x*x+y*y) <= 1
reject = np.logical_not(accept)
fig, ax = plt.subplots(1)
ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)
ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)
ax.set_aspect('equal')
```

Il est alors aisé d’obtenir une approximation (pas terrible) de $
\p
i$ en comptant combien de fois,
en moyenne, X
<sup>
2
</sup>
+ Y
<sup>
2
</sup>
est inférieur à 1 :
```python
4*np.mean(accept)
```
3.112
module2/exo1/output_12_0.png
0 → 100644
View file @
3c08d49c
37.2 KB
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