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
f5e2241d8848f9714c95e4f99428f546
mooc-rr
Commits
32a618d0
Commit
32a618d0
authored
Jul 07, 2020
by
Dorinel Bastide
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proceeded to changes following comparison with solution
parent
d4b18a45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
18 deletions
+12
-18
toy_document_orgmode_python_en.org
module2/exo1/toy_document_orgmode_python_en.org
+12
-18
No files found.
module2/exo1/toy_document_orgmode_python_en.org
View file @
32a618d0
...
...
@@ -11,42 +11,36 @@
#+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>
* Table of Contents
#+PROPERTY: header-args :session :exports both
1. Asking the math libraryo
2. * Buffon's needle
3. Using a surface fraction argument
* 1 Asking the math library
* Asking the math library
My computer tells me that $\pi$ is /approximatively/
#+begin_src python :results
output
:exports both
import math
p
rint(math.pi)
#+begin_src python :results
value :session *python*
:exports both
from math import *
p
i
#+end_src
#+RESULTS:
: 3.141592653589793
*
2
* Buffon's needle
Applying the method of [[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's needle]], we get the
approximation
* * Buffon's needle
Applying the method of [[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's needle]], we get the
*approximation*
#+begin_src python :results output :exports both
import math
#+begin_src python :results value :session *python* :exports both
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=
math.
pi/2)
print(2/(sum((x+np.sin(theta))>1)/N)
)
theta = np.random.uniform(size=N, low=0, high=pi/2)
2/(sum((x+np.sin(theta))>1)/N
)
#+end_src
#+RESULTS:
: 3.128911138923655
* 3. Using a surface fraction argument
A method that is easier to understand and does not make use of the
$\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim
* Using a surface fraction argument
A method that is easier to understand and does not make use of the $\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim
U(0,1)$, then $P[X^2 + Y^2 \leq 1]=\pi/4$ (see [[https://en.wikipedia.org/wiki/Monte_Carlo_method]["Monte Carlo method"
on Wikipedia]]). The following ocde uses this approach:
#+begin_src python :results output file :session :var matplot_lib_filename="C:/Users/Utilisateur/mooc-rr/module2/exo1/PictureRes.png" :exports results
...
...
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