n=84
p=0.3
m=n*p
s=sqrt(n*p*(1-p))

function y=gauss_kernel(x)
  y=exp(-x^2/2)/((2*%pi)^0.5)
endfunction

t_init=0:n
t_init_mod=(0:n)-m

t=(t_init-m)./s
t_fin=(-1000:1000)/100

y_init=binomial(p,n)
y_init_mod=y_init
y_fin=y_init*s
    
ya=zeros(2001)
for i=1:2001
  ya(i)=gauss_kernel(t_fin(i))
end

clf()


  
subplot(3,1,1)
plot(t_init,y_init,'b')

xtitle('Variable de départ X', '', 'Probabilités')
latex1='$\begin{array}{lcccl} X & \sim & \mathcal{B}('+string(n)+','+string(p)+')\\ \mu & = & np & = & '+string(n*p)+'\\ \sigma & = & \sqrt{np(1-p)} & = & '+string(sqrt(n*p*(1-p)))+'\end{array}$'
xstring(50,0.01,latex1)
e=gce()
e.font_size=3

subplot(3,1,2)
plot(t_init_mod,y_init_mod,'b')
xtitle('Variable centrée Y', '', 'Probabilités')
latex1='$Y=X-\mu=X-'+string(n*p)+'$'
xstring(20,0.04,latex1) 
e=gce()
e.font_size=3


subplot(3,1,3)
plot(t,y_fin,'b')
plot(t_fin,ya,'g')
xtitle('Variable centrée réduite Z', '', 'Probabilités')
latex2='$Z = \dfrac{X-np}{\sqrt{n p (1-p)}}=\dfrac{X-'+string(n*p)+'}{'+string(sqrt(n*p*(1-p)))+'}$'
xstring(4,0.2,latex2)
e=gce()
e.font_size=3

f=gcf()
f.figure_name = 'Approximation d''une loi binomiale par le théorème de Moivre-Laplace"
f11=f.children(1).children(3).children(1)
f11.polyline_style=3
f11.line_mode='off'
f.children(1).title.font_size=3
f.children(1).y_label.font_size=2
//t11=f11.title

f12=f.children(2).children(2).children(1)
f12.polyline_style=3
f12.line_mode='off'
f.children(2).title.font_size=3
f.children(2).y_label.font_size=2

f13=f.children(3).children(2).children(1)
f13.polyline_style=3
f13.line_mode='off'
f.children(3).title.font_size=3
f.children(3).y_label.font_size=2
