%------------------------
% Author: Kiril Zvezdarov
% Excercise 4.2
% Course: CIS 2033
% Purpose: Draws three plots of the Cumulative and Mass Functions of
%          the Binomial and Geometric distributions. Binomial is in red,
%          geometric is in blue. The cumulative functions are labeled with + signs
% License: GPLv3
% Date: 22/02/2013
%------------------------

function [y] = BinGraphCDF( total, p)
    for i = 1:total
        y(i) = binocdf(i, total, p);
    end
end

function [y] = GeoGraphCDF(total, p)
    for i = 1:total
        y(i) = geocdf(i, p)
    end
end

function [y] = GeoGraphMass(total, p)
    for i = 1:total
        y(i) = p*(1-p)^(i-1)
    end
end

function [y] = BinGraphMass(total, p)
    for i = 1:total
        y(i) = nchoosek(total,i)*p^i*(1-p)^(total-i)
    end
end

prob_range = [0.3,0.5,0.6,]
x_range=1:30

for i = 1:3
    p =prob_range(i) 
    yBinCdf = BinGraphCDF(30, p)
    yGeoCdf = GeoGraphCDF(30, p)
    yBinMass = BinGraphMass(30, p)
    yGeoMass = GeoGraphMass(30,p)
    title(p)
    subplot(3,1,i); plot(x_range,yBinMass, 'r', x_range, yGeoMass, 'b', x_range, yBinCdf, 'r+', x_range, yGeoCdf, 'b+')

end

pause()
    




