n = 400; p = 0.4;
sondage = int(rand(1, n) + p);
fe1 = sum(sondage)/n;

sondage2 = grand(1, n, 'bin', 1, p);
fe2 = sum(sondage2)/n;

sondages = int(rand(100, n) + p);
fe = sum(sondages, 'c')/n;
histplot(15, fe);

moyenne = mean(fe);
mediane = median(fe);

ecartType = stdev(fe);
q = quart(fe);
interQuartile = q(3) - q(1);

entreMinMax = fe(min(fe) <= fe & fe < max(fe));
nbEntreMinMax = length(entreMinMax);

nbMax = length(fe) - nbEntreMinMax;

entreQuartiles = fe(q(1) <= fe & fe < q(3));
nbEntreQuartiles = length(entreQuartiles);

proportionEntreQuartiles = nbEntreQuartiles/length(fe);

ecartTypeTheo = sqrt(p*(1-p)/n);
distanceRelative = (ecartType - ecartTypeTheo)/ecartTypeTheo;

ftheo = p*ones(100, 1);
feinf = fe - 1.96*ecartType;
fesup = fe + 1.96*ecartType;

xset("window", 1);
i = 1:100; 
plot2d(i, feinf(i)); 
plot2d(i, ftheo(i)); 
plot2d(i, fesup(i));

nbIntervallesFaux = sum(bool2s(ftheo < feinf | ftheo > fesup));

feinf10pc = fe - 1.64*ecartType;
fesup10pc = fe + 1.64*ecartType;

xset("window", 2);
plot2d(i, feinf10pc(i)); 
plot2d(i, ftheo(i)); 
plot2d(i, fesup10pc(i));

nbIntervallesFaux10pc = sum(bool2s(ftheo < feinf10pc | ftheo > fesup10pc));

n = 1000; 
sondage1000 = int(rand(1, n) + p);
fe1000 = sum(sondage1000)/n;
ecartTypeTheo1000 = sqrt(p*(1-p)/n);
intMin5pc = fe1000 - 1.96*ecartTypeTheo1000;
intMax5pc = fe1000 + 1.96*ecartTypeTheo1000;
intMin10pc = fe1000 - 1.64*ecartTypeTheo1000;
intMax10pc = fe1000 + 1.64*ecartTypeTheo1000;

sondages1000 = int(rand(100, n) + p);
fe1000 = sum(sondages1000, 'c')/n;

xset("window", 0);
histplot(15, fe1000);
moyenne1000 = mean(fe1000);
moyenneTheo1000 = p;
ecartType1000 = stdev(fe1000);
distanceRelative = (ecartType1000 - ecartTypeTheo1000)/ecartTypeTheo1000;

ftheo1000 = moyenneTheo1000*ones(100, 1);
feinf1000 = fe1000 - 1.96*ecartType1000;
fesup1000 = fe1000 + 1.96*ecartType1000;

nbIntervallesFaux1000 = sum(bool2s(ftheo1000 < feinf1000 | ftheo1000 > fesup1000));

ftheo1000 = moyenneTheo1000*ones(100, 1);
feinf1000 = fe1000 - 1.64*ecartType1000;
fesup1000 = fe1000 + 1.64*ecartType1000;

nbIntervallesFaux1000 = sum(bool2s(ftheo1000 < feinf1000 | ftheo1000 > fesup1000));

n = 10000;
sondages10000 = int(rand(100, n) + p);
fe10000 = sum(sondages10000, 'c')/n;
ecartType10000 = stdev(fe10000);

ftheo10000 = p*ones(100, 1);
feinf10000 = fe10000 - 1.64*ecartType10000;
fesup10000 = fe10000 + 1.64*ecartType10000;

nbIntervallesFaux10000 = sum(bool2s(ftheo10000 < feinf10000 | ftheo10000 > fesup10000));

