Source Latex:


Fichier
Type: Programme python
File type: Latex, tex (source)
Télécharger le document pdf compilé pdficon
Description
Travaux pratiques et programmation: planche de Galton
Mots clé
TP python, planche de Galton, programmtion, python
Voir aussi:

Documentation sur LaTeX
lien vers la documentation Latex
Source LaTex icone

Source Latex

\documentclass[12pt]{article}
%\usepackage{french}
\usepackage{amsfonts}\usepackage{amssymb}


\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\usepackage{a4wide}
\usepackage{graphicx}
\usepackage{epsf}
\usepackage{calc}
\usepackage{enumerate}

\usepackage{array}
\usepackage{multirow}
\usepackage{longtable}
%\usepackage[table]{xcolor}
%\usepackage{pst-plot,pst-text,pst-tree}
\usepackage{pst-all}
\usepackage{pstricks-add}
\usepackage{pst-func}

\usepackage{ifthen}

\usepackage{hyperref}
\hypersetup{
    pdfauthor={Yoann Morel},
    pdfsubject={TP Planche de Galton},
    pdftitle={TP Planche de Galton},
    pdfkeywords={Mathématiques, TS, terminale, S, 
      probabilité, probabilités, 
      Galton, planche de Galton, 
      Moivre-Laplace, théorème de Moivre-Laplace, 
      loi binomiale, loi normale, 
      TICE, algorithmique, 
      programme TI, python, programme python
    }
}
\hypersetup{
    colorlinks = true,
    linkcolor = red,
    anchorcolor = red,
    citecolor = blue,
    filecolor = red,
    urlcolor = red
}
\voffset=-1cm
% Raccourcis diverses:
\newcommand{\nwc}{\newcommand}
\nwc{\dsp}{\displaystyle}
\nwc{\ct}{\centerline}
\nwc{\bge}{\begin{equation}}\nwc{\ene}{\end{equation}}
\nwc{\bgar}{\begin{array}}\nwc{\enar}{\end{array}}
\nwc{\bgit}{\begin{itemize}}\nwc{\enit}{\end{itemize}}
\nwc{\bgen}{\begin{enumerate}}\nwc{\enen}{\end{enumerate}}

\nwc{\la}{\left\{}\nwc{\ra}{\right\}}
\nwc{\lp}{\left(}\nwc{\rp}{\right)}
\nwc{\lb}{\left[}\nwc{\rb}{\right]}

\nwc{\bgsk}{\bigskip}
\nwc{\vsp}{\vspace{0.1cm}}
\nwc{\vspd}{\vspace{0.2cm}}
\nwc{\vspt}{\vspace{0.3cm}}
\nwc{\vspq}{\vspace{0.4cm}}

\def\N{{\rm I\kern-.1567em N}}                              % Doppel-N
\def\D{{\rm I\kern-.1567em D}}                              % Doppel-N
\def\No{\N_0}                                               % Doppel-N unten 0
\def\R{{\rm I\kern-.1567em R}}                              % Doppel R
\def\C{{\rm C\kern-4.7pt                                    % Doppel C
\vrule height 7.7pt width 0.4pt depth -0.5pt \phantom {.}}}
\def\Q{\mathbb{Q}}
\def\Z{{\sf Z\kern-4.5pt Z}}                                % Doppel Z

\def\epsi{\varepsilon}
\def\vphi{\varphi}
\def\lbd{\lambda}
\def\Ga{\Gamma}

\def\Cf{\mathcal{C}_f}

\nwc{\tm}{\times}
\nwc{\V}[1]{\overrightarrow{#1}}

\nwc{\zb}{\mbox{$0\hspace{-0.67em}\mid$}}
\nwc{\db}{\mbox{$\hspace{0.1em}|\hspace{-0.67em}\mid$}}

\nwc{\ul}[1]{\underline{#1}}

%\newenvironment{proof}{
%  \noindent\textsc{Preuve.~}}{\hfill$\square$\bigbreak} 
\nwc{\bgproof}[1]{%
  \vspt\noindent%
  \ul{Démonstration:} #1%
  \hfill$\square$%
}

\newcounter{nex}%[section]
\setcounter{nex}{0}
\newenvironment{EX}{%
\stepcounter{nex}
\bgsk{\noindent\large {\bf Exercice }\arabic{nex}}\hspace{0.2cm}
}{}

\nwc{\bgex}{\begin{EX}}\nwc{\enex}{\end{EX}}

\nwc{\bgfg}{\begin{figure}}\nwc{\enfg}{\end{figure}}
  \nwc{\epsx}{\epsfxsize}\nwc{\epsy}{\epsfysize}
\nwc{\bgmp}{\begin{minipage}}\nwc{\enmp}{\end{minipage}}


\nwc{\limcdt}[4]{
  $\dsp
  \lim_{\bgar{ll}\scriptstyle{#1}\vspace{-0.2cm}\\\scriptstyle{#2}\enar}
  {#3}={#4}$
}
\nwc{\tq}{\ \mbox{\bf\Large /}\ }

\nwc{\PI}{\hspace*{0.3cm}}
\nwc{\DPI}{\hspace*{0.6cm}}
\nwc{\TPI}{\hspace*{0.9cm}}


\headheight=0cm
\textheight=26cm
\topmargin=-1.8cm
\footskip=1.cm
\textwidth=18cm
\oddsidemargin=-1cm

\setlength{\unitlength}{1cm}

\newcounter{ntheo}
\setcounter{ntheo}{1}
\newlength{\ltheo}
\nwc{\bgth}[1]{
  \settowidth{\ltheo}{Théorème \arabic{ntheo}}
  \noindent
  \paragraph{Théorème}% \arabic{ntheo}}
  \hspace{-0.5em}%\hspace{-0.4cm}
  \bgmp[t]{\textwidth-\ltheo-0.5em}{\it #1}\enmp
  \stepcounter{ntheo}
}

\newcounter{nprop}
\setcounter{nprop}{1}
\newlength{\lprop}
\nwc{\bgprop}[1]{
  \settowidth{\lprop}{Propriété \arabic{nprop}}
  \noindent
  \paragraph{Propriété}% \arabic{ntheo}}
  \hspace{-0.5em}%\hspace{-0.4cm}
  \bgmp[t]{\textwidth-\lprop-0.5em}{\it #1}\enmp
  \stepcounter{nprop}
}

\nwc{\bgcorol}[1]{
  \settowidth{\ltheo}{Corollaire \arabic{ntheo}}
  \noindent
  \paragraph{Corollaire}% \arabic{ntheo}}
  \hspace{-0.5em}%\hspace{-0.4cm}
  \bgmp[t]{\textwidth-\ltheo-0.5em}{\it #1}\enmp
}

\newcounter{ndef}
\setcounter{ndef}{1}
\newlength{\ldef}
\nwc{\bgdef}[1]{
  \settowidth{\ldef}{Définition \arabic{ndef}}
  \noindent
  \paragraph{Définition}% \arabic{ndef}}
  \hspace{-0.5em}%\hspace{-0.4cm}
  \bgmp[t]{\textwidth-\ldef-0.5em}{\it #1}\enmp
  \stepcounter{ntheo}
}


\renewcommand\thesection{\Roman{section}\ \ -}
\renewcommand\thesubsection{\arabic{subsection})}

% Bandeau en bas de page
\newcommand{\TITLE}{La planche de Galton}
\author{Y. Morel}
\date{}

\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancyplain}
\setlength{\headheight}{0cm}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.1pt}
\lhead{}\chead{}\rhead{}

\lfoot{Y. Morel \url{https://xymaths.fr/Lycee/TS/}}
\rfoot{\TITLE\ - \thepage/\pageref{LastPage}}
%\cfoot{\TITLE\ - \ $T^{\mbox{\scriptsize{ale}}}S$}
\cfoot{}


%% Environnement TP_Titre:
\nwc{\TPtop}{}
\newlength{\lgr}
\newlength{\TPtopLarge}
\newlength{\EXX}
\newlength{\Tlgr}
\newlength{\TopHeight}
\newlength{\TopTitleHeight}

\newcommand{\ChapTitle}[3]{
  \renewcommand{\TPtop}{{\LARGE\bf #1} {\Huge\bf#2}}
  \settowidth{\lgr}{\LARGE\bf #1}
  \settowidth{\TPtopLarge}{\TPtop}
  \settoheight{\EXX}{\LARGE X}
  \settowidth{\Tlgr}{\LARGE T}
  \setlength{\Tlgr}{0.5\Tlgr}
  \settototalheight{\TopHeight}{\fbox{\bgmp{\linewidth}\begin{center}{\LARGE\bf#3}\end{center}\enmp}}
  %\setlength{\TopHeight}{\TopHeight+\EXX}
  %\settoheight{\TopTitleHeight}{#3}
  %%
  \noindent
  \bgmp{\linewidth}
  \psline(\lgr,\EXX)(1.1\lgr,\EXX)
  \psline(\TPtopLarge,\EXX)(\linewidth,\EXX)%
  (\linewidth,-1.\TopHeight)(\Tlgr,-1.\TopHeight)%
  (\Tlgr,-0.05)
  \TPtop
  \vspace{-.5\EXX}
  \begin{center}
    {\LARGE\bf#3}
  \end{center}
  \enmp%
  \vspace{0.5cm}
}
%% Fin TP_Titre
%
%% Environnement Prog
\definecolor{grayp}{gray}{0.8}
\definecolor{graypc}{gray}{0.65}
\newlength{\hgn}\newlength{\hgnp}
\newlength{\hgng}
\newlength{\lgn}\newlength{\lgng}
\newlength{\hgtq}\newlength{\hgtqg}
\newlength{\lgtq}\newlength{\lgtqg}
\newlength{\lgcoin}\setlength{\lgcoin}{3ex}
\newlength{\lgshadow}\setlength{\lgshadow}{0.5ex}
\newlength{\phgn}\newlength{\phgnp}
\newlength{\phgng}
\newlength{\plgn}\newlength{\plgng}
\newlength{\phgtq}\newlength{\phgtqg}
\newlength{\plgtq}\newlength{\plgtqg}
\newlength{\plgcoin}\setlength{\plgcoin}{3ex}
\newlength{\plgshadow}\setlength{\plgshadow}{0.5ex}
\makeatletter
\def\Prog{\@ifnextchar[{\@with}{\@without}}
  % avec un argument optionnel: le titre: 
  \def\@with[#1]#2#3{%
  \par%\vspd%
  \bgmp{\linewidth}
  \hspace*{-0.3pt}\hspace*{-\parindent}\hspace*{-1ex}%
  \psframebox[fillstyle=solid,fillcolor=graypc]{
    \emph{\textcolor{white}{\!\!\!\! #1}}} \\
  \vspace*{-0.5ex}\\
  \bgmp{#2}
  %\setlength{\fboxrule}{0.1pt}
  \settototalheight{\phgn}{\phantom{\bgmp{#2}#3\enmp}}
  \setlength{\plgn}{\linewidth}
  \setlength{\phgtq}{-\phgn}%\addtolength{\hgtq}{-3ex}
  \setlength{\phgtqg}{\phgtq}\addtolength{\phgtqg}{-\lgshadow}
  \setlength{\plgng}{\plgn}\addtolength{\plgng}{\lgshadow}
  \setlength{\plgtq}{\plgn}\addtolength{\plgtq}{-\lgcoin}
  \setlength{\plgtqg}{\plgtq}\addtolength{\plgtqg}{\lgshadow}
  \setlength{\phgnp}{\phgn}\addtolength{\phgnp}{\lgcoin}
  \setlength{\phgng}{\phgnp}\addtolength{\phgng}{\lgshadow}
  \pspolygon[linecolor=white,fillstyle=solid,fillcolor=grayp]%
  (-1ex,-\phgnp)(-1ex,1ex)(\plgn,1ex)(\plgng,0)%
  (\plgng,\phgtqg)(\plgtqg,-\phgng)(-0.5ex,-\phgng)
  \pspolygon[linewidth=0.6pt,linecolor=graypc,fillstyle=solid,fillcolor=graypc]%
  (\plgn,\phgtq)(\plgtq,\phgtq)(\plgtq,-\phgnp)
  \pspolygon[fillstyle=solid,fillcolor=white]%
  (-1ex,-\phgnp)(-1ex,1ex)(\plgn,1ex)%
  (\plgn,\phgtq)(\plgtq,\phgtq)(\plgtq,-\phgnp)
  \par
  \bgmp{\linewidth}#3\enmp
  \enmp
  \enmp
  \vspd
  }
  % sans argument optionnel: le titre est alors "Programme Python"
  \def\@without#1#2{%
  \par%\vspd%
  \bgmp{\linewidth}
  \hspace*{-0.3pt}\hspace*{-\parindent}\hspace*{-1ex}%
  \psframebox[fillstyle=solid,fillcolor=graypc]{
    \emph{\textcolor{white}{\!\!Programme Python}}} \\
  \vspace*{-0.5ex}\\
  \bgmp{#1}
  %\setlength{\fboxrule}{0.1pt}
  \settototalheight{\phgn}{\phantom{\bgmp{#1}#2\enmp}}
  \setlength{\plgn}{\linewidth}
  \setlength{\phgtq}{-\phgn}%\addtolength{\hgtq}{-3ex}
  \setlength{\phgtqg}{\phgtq}\addtolength{\phgtqg}{-\lgshadow}
  \setlength{\plgng}{\plgn}\addtolength{\plgng}{\lgshadow}
  \setlength{\plgtq}{\plgn}\addtolength{\plgtq}{-\lgcoin}
  \setlength{\plgtqg}{\plgtq}\addtolength{\plgtqg}{\lgshadow}
  \setlength{\phgnp}{\phgn}\addtolength{\phgnp}{\lgcoin}
  \setlength{\phgng}{\phgnp}\addtolength{\phgng}{\lgshadow}
  \pspolygon[linecolor=white,fillstyle=solid,fillcolor=grayp]%
  (-1ex,-\phgnp)(-1ex,1ex)(\plgn,1ex)(\plgng,0)%
  (\plgng,\phgtqg)(\plgtqg,-\phgng)(-0.5ex,-\phgng)
  \pspolygon[linewidth=0.6pt,linecolor=graypc,fillstyle=solid,fillcolor=graypc]%
  (\plgn,\phgtq)(\plgtq,\phgtq)(\plgtq,-\phgnp)
  \pspolygon[fillstyle=solid,fillcolor=white]%
  (-1ex,-\phgnp)(-1ex,1ex)(\plgn,1ex)%
  (\plgn,\phgtq)(\plgtq,\phgtq)(\plgtq,-\phgnp)
  \par
  \bgmp{\linewidth}#2\enmp
  \enmp
  \enmp
  \vspd
  }
\makeatother
% les petits caracteres casio:
\nwc{\return}{
  \psset{unit=1cm,arrowsize=4pt}
  \psline{<-}(0,0.1)(0.3,0.1)(0.3,0.25)}
\nwc{\disp}{\pspolygon[fillstyle=solid,fillcolor=black](0,0)(0.2,0)(0.2,0.15)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

%\bgTP{Méthode de Monté Carlo}
\section*{}
\ChapTitle{TP}{}{La planche de Galton \\ 
\large{Illustration "naturelle" du théorème de Moivre-Laplace}\\ \ }
%\addcontentsline{toc}{section}{\ul{TP 1 :}\ Méthode de Monté Carlo}
%\rfoot{Méthode de Monté Carlo}


La planche de Galton est un dispositif inventé par 
Sir Francis Galton (1822-1911),  homme de science
britannique cousin de Darwin: anthropologue, explorateur, géographe, inventeur,
météorologue, psychométricien et statisticien. 

Il est entre autres fondateur de la psychologie différentielle ou
comparée. Il a également mis en place de façon systématique la méthode
d'identification des individus par empreintes digitales. 

Galton voulait justifier la transmission des capacités intellectuelles
par l'hérédité pour permettre l'amélioration de l'espèce humaine. 
Il est par ailleurs considéré comme le fondateur de l'eugénisme. 

\vspd
Des clous sont plantés en quinconce sur une planche, en haut de laquelle des billes 
sont successivement lâchées. 
A la rencontre d'un clou, chaque bille passe soit à droite
soit à gauche, équiprobablement, pour accéder à la rangée inférieure
de clous. 

En bas de la planche, les billes se rassemblent en fonction du nombre
de passages à gauche 
et à droite qu'elles ont fait. 



\psset{unit=1cm}
\begin{pspicture}(-8,0)(8,10)
  %  \multido{\i=-5+1}{10}{
  %  \pscircle[fillstyle=solid,fillcolor=black](\i,1){0.2}
  %}
  %% Motif de base: "clou"
  %\psline[linewidth=1.4pt](0,0)(0.15,0.25)
  %\psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  %%
  %
  %\multido{\il=-5+1}{10}{
  %  \multido{\ic=-\il+1}{2\il}{
  %    \rput(! \il \space \ic){
  %    \psline[linewidth=1.4pt](0,0)(0.15,0.25)
  %    \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  %  }}
  \multido{\il=-4+1}{8}{
    \rput(\il,1){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \nwc\f[1]{#1 0.5 sub}
  \multido{\il=-3+1}{7}{
    \rput(! \f{\il} \space 2){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \multido{\il=-3+1}{6}{
    \rput(! \il \space 3){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \multido{\il=-2+1}{5}{
    \rput(! \f{\il} \space 4){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \multido{\il=-2+1}{4}{
    \rput(! \il \space 5){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \multido{\il=-1+1}{3}{
    \rput(! \f{\il} \space 6){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \multido{\il=-1+1}{2}{
    \rput(! \il \space 7){
      \psline[linewidth=1.4pt](0,0)(0.15,0.25)
      \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }}
  \rput(-0.5,8){
    \psline[linewidth=1.4pt](0,0)(0.15,0.25)
    \psellipse[fillstyle=solid,fillcolor=black](0.15,0.25)(0.12,0.08)
  }
  %\pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(0.3,0.5)},gradmidpoint=1](0,0){1}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-0.3,9.5)},gradmidpoint=1](-0.4,9.4){.25}
  \psline[linewidth=1.2pt,arrowsize=6pt]{->}(-0.4,9.1)(-0.4,8.6)
  \psline[linewidth=1.2pt,arrowsize=6pt]{->}(-0.7,8.1)(-1.1,7.5)
  \psline[linewidth=1.2pt,arrowsize=6pt]{->}(-0.1,8.1)(0.3,7.5)
  %
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-1.3,4.8)},gradmidpoint=1](-1.4,4.7){.25}
  \psline[linewidth=1.2pt,arrowsize=6pt]{->}(-1.7,4)(-2.1,3.4)
  \psline[linewidth=1.2pt,arrowsize=6pt]{->}(-1.1,4)(-0.7,3.4)
  %
  % Et la planche de récup tout en bas:
  \psline[linewidth=1.5pt](-5.,-0.5)(4.,-0.5)
  \multido{\i=-5+1}{10}{
    \psline(! \i \space -0.5)(! \i \space 0.)
  }
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-.15,-0.15)},gradmidpoint=1](-.25,-0.25){.25}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-0.65,-0.15)},gradmidpoint=1](-0.75,-0.25){.25}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-0.4,0.3)},gradmidpoint=1](-0.5,0.2){.25}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(-2.4,-0.15)},gradmidpoint=1](-2.5,-0.25){.25}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(1.6,-0.15)},gradmidpoint=1](1.5,-0.25){.25}
  \pscircle[fillstyle=gradient,GradientCircle=true,gradbegin=white,gradend=black,GradientPos={(2.65,-0.15)},gradmidpoint=1](2.5,-0.25){.25}

\end{pspicture}

\vspt
\Prog[Algorithme]{16cm}{
\texttt{%
Affecter à N la valeur\\
Affecter à S la valeur 10\\
Affecter à la liste 1 les valeurs de 1 à 2*S\\
Initialiser la liste 2 avec 2*S valeurs nulles\\
Pour i allant de 1 à N\\
\PI Affecter à P la valeur S\\
\PI Pour j allant de 1 à S\\
\DPI Affecter à R un nombre aléatoire de $[0;1]$\\
\DPI Si R>0.5\\
\TPI Alors Affecter à P la valeur P+1\\
\TPI Sinon Affecter à P la valeur P-1\\
\DPI Fin SI\\
\PI Fin Pour (boucle j)\\
\PI Incrémenter la p-ème valeur de la liste 2\\
Fin Pour (boucle i)\\
\newline
Tracer sur un graphique les points dont les abscisses sont les valeurs
de la liste 1 et les ordonnées les valeurs de la liste 2
%de coordonnées $\bigr($liste 1[i],list 2[i]$\bigl)$
}
}

\vspace{0.6cm}
\bgmp{6cm}
\Prog[Programme Casio]{6cm}{
\texttt{%
50$\to$N\return\\
10$\to$S\return\\
Seq(X,X,1,2*S,1)$to$List 1\return\\
Seq(0,X,1,2*S,1)$to$List 2\return\\
For 1$\to$I To N\return\\
S$\to$P\return\\
For 1$\to$J To S\return\\
Ran\#$\to$R\return\\
If R>0.5\return\\
Then P+1$\to$P\return\\
Else P-1$\to$P\return\\
IfEnd\return\\
Next\return\\
List 2[P]+1$\to$List 2[P]\return\\
Next\return\\
List 2\disp
}
}
\enmp\hfill
\bgmp{10.5cm}
\Prog{10.5cm}{
\texttt{%
from pylab import * \# pour les graphiques\\
import random \quad      \# pour les fonctions aleatoires\\
\newline
N=50000 \# nombre de billes lachees\\
L=150 \# nombre de lignes de la planche\\
\#L=1\ \ \     *\\
\#L=2\ \   * *\\
\#L=3\   * * *\\
\#L=4  * * * *\\
\#\dots\\
List=[0,]*(2*L)\\
\newline
for n in range(N):\\
\PI    pos=L \# initialement, la bille est centree\\
\PI    for l in range(L):\\
\DPI        r=random.random()\\
\DPI        if r>0.5: pos=pos+1 \# la bille va a droite\\
\DPI        else: pos=pos-1     \# sinon a gauche\\
\PI    List[pos]=List[pos]+1\\
\newline
plot(range(-L,L),List,'*')\\
show()
}
}
\enmp




%\enTP
\end{document}

Télécharger le fichier source Latex