%disbin.m
%distribuzione binomiale
clear
n=6;
ft(1)=1;
for i=2:n
    ft(i)=ft(i-1)*i;
end
subplot(1,2,1);
p=0.3;
q=1-p;
pb(1)=q^n;
for i=1:n-1
    pb(i+1)=ft(n)/(ft(i)*ft(n-i))*(p^i)*(q^(n-i));
end
pb(n+1)=p^n;
x=[0:1:n];
bar(x,pb)
axis([-1 7 0 0.35])
xlabel('n')
text(4.5,0.3,'a) p=0.3')

subplot(1,2,2);
p=0.5;
q=1-p;
pb(1)=q^n;
for i=1:n-1
    pb(i+1)=ft(n)/(ft(i)*ft(n-i))*(p^i)*(q^(n-i));
end
pb(n+1)=p^n;
x=[0:1:n];
bar(x,pb)
axis([-1 7 0 0.35])
xlabel('n')
text(4.5,0.3,'b) p=0.5')