Un arbre de Bernoulli à 2 niveaux

bernoulli2.jpg

Voici son code :

input geometriesyr16.mp ;


%%%%%%%%%%%%%%%%%%
%%
%%Ne pas oublier : export TEX=latex
%%
%%%%%%%%%%%%%%%%%

vardef TEX primary s =
  write "verbatimtex"   to "mptextmp.mp";
  write "%&latex" to  "mptextmp.mp";
  write "\documentclass{article}"  to "mptextmp.mp";
  write "\usepackage{aeguill}" to "mptextmp.mp";
  write "\usepackage[frenchb]{babel}" to "mptextmp.mp";
  write "\usepackage{amsmath}" to "mptextmp.mp";
  write "\usepackage{amsfonts}" to "mptextmp.mp";
  write "\begin{document}"  to "mptextmp.mp";
  write "etex"    to "mptextmp.mp";
  write "btex " & s & " etex" to "mptextmp.mp";
  write EOF to "mptextmp.mp";
  scantokens "input mptextmp"
enddef;

%------------------------------------------------------------------------
% Arbre de Bernoulli à deux niveaux
%------------------------------------------------------------------------


u:=1cm;
figure (-8u,-8u,10u,8u);
pair S,T[],U[];

numeric dx,dh,cr;
dx:=3;
dh:=1.5;
cr:=0.1;

for i:=1 upto 4:
  U[i]:=(2*dx*u,-i*dh*u);
endfor

T[1]:= 0.5[U[1],U[2]] shifted(-dx*u,0);
T[2]:= 0.5[U[3],U[4]] shifted(-dx*u,0);

S:= 0.5[T[1],T[2]] shifted(-dx*u,0);

draw cr[S,T[1]]--(1-cr)[S,T[1]];
draw cr[S,T[2]]--(1-cr)[S,T[2]];
draw cr[T[1],U[1]]--(1-cr)[T[1],U[1]];
draw cr[T[1],U[2]]--(1-cr)[T[1],U[2]];
draw cr[T[2],U[3]]--(1-cr)[T[2],U[3]];
draw cr[T[2],U[4]]--(1-cr)[T[2],U[4]];


string a,na,pa,pna;
a:="$A$";
na:="$\overline{A}$";
pa:="$\frac{1}{3}$";
pna:="$\frac{2}{3}$";

%----------- premier niveau
label(TEX a,T[1]);
label.ulft(TEX pa,0.6[S,T[1]]);

label(TEX na,T[2]);
label.llft(TEX pna,0.6[S,T[2]]);

%----------- deuxième niveau supérieur
label(TEX a,U[1]);
label.ulft(TEX pa,0.6[T[1],U[1]]);

label(TEX na,U[2]);
label.llft(TEX pna,0.6[T[1],U[2]]);

%----------- deuxième niveau inférieur
label(TEX a,U[3]);
label.ulft(TEX pa,0.6[T[2],U[3]]);

label(TEX na,U[4]);
label.llft(TEX pna,0.6[T[2],U[4]]);


fin;
%-----------------------------------------------------------------------


%-----------------------------------------------------------------------
end ;


Niveau supérieur : Arbres de probabilité