
%% Binomisk mot normal

figure

nmax=20

subplot(8,1,8)

xlabel('n', 'fontsize', 16)

set(gca,'nextplot','replacechildren');
for n = 1:nmax
subplot(8,1,1:6)

bar(0:1:nmax,binopdf(0:1:nmax,n,0.4),1,'y' )
hold
axis([-0.5 20 0 0.8]);
plot(-0.5:0.1:20, normpdf(-0.5:0.1:20, n*0.4, sqrt(n*0.4*0.6)), 'LineWidth',2)
legend('Binomisk(n,p)', 'Normal(n*p, n*p*(1-p))')
xlabel('x', 'fontsize', 16)
ylabel('f(x)', 'fontsize', 16)
title('Binomisk mot normal, p=0.4')
hold
subplot(8,1,8)
plot(n,0.5,'*')
axis([0 nmax 0 1])

F3(n)=getframe(gcf);
end


%% Poisson mot normal

figure

subplot(8,1,8)

lambdamax=10

xlabel('lambda', 'fontsize', 16)

set(gca,'nextplot','replacechildren');


for lambda = 1:lambdamax
subplot(8,1,1:6)

bar(0:1:2*lambdamax,poisspdf(0:1:2*lambdamax,lambda),1,'y' )
hold
axis([-0.5 20 0 0.8]);
plot(-0.5:0.1:20, normpdf(-0.5:0.1:20, lambda, sqrt(lambda)), 'LineWidth',2)
legend('Poisson(lambda)', 'Normal(lambda, lambda)')
xlabel('x', 'fontsize', 16)
ylabel('f(x)', 'fontsize', 16)
title('Poisson mot normal')
hold
subplot(8,1,8)
plot(lambda,0.5,'*')
axis([0 lambdamax 0 1])

F3(n)=getframe(gcf);
end




%% Plottar Gamma fordeling saman med normal
a=10;
b=100;
%% Finn passande x-verdiar:
x = gaminv((0.005:0.01:0.995),a,b);
y = gampdf(x,a,b);
y1 = normpdf(x,a*b,b^2);
plot(x,y,'-',x,y1,'-.','LineWidth',2)
legend('Gamma, a=10, b=100','Normal, \mu=ab, \sigma^2=b^2')

