% True parameters
mu = 180;
sig = 10;

% Control random number generator
rng(1002)

% Sample 1
x1 = randn(5,1)*sig+mu;
mu1 = mean(x1)
sig1 = var(x1)

% Sample 2
x2 = randn(5,1)*sig+mu;
mu2 = mean(x2)
sig2 = var(x2)

% Exponential distribution
xs = linspace(0, 10, 10000);
y1 = pdf('gam', xs, 1, 1);
y5 = pdf('gam', 5*xs, 5, 1);
y10 = pdf('gam', 10*xs, 10, 1);
y30 = pdf('gam', 30*xs, 30, 1);

close all;
plot(xs, y1, 'LineWidth', 3);
set(gca, 'FontSize', 24);
ylabel('Sannsynlighetstetthet', 'FontSize', 24);
hold on;
plot(xs, y5*5, 'LineWidth', 3);
plot(xs, y10*10, 'LineWidth', 3);
plot(xs, y30*30, 'LineWidth', 3);
legend('n = 1', 'n = 5', 'n = 10', 'n = 30');
title('Empirisk middelverdi', 'FontSize', 28);
print('-dpdf', 'CLT.pdf')

yNorm = pdf('norm', xs, 1, sqrt(1/30));
plot(xs, yNorm, 'LineWidth', 3);
legend('n = 1', 'n = 5', 'n = 10', 'n = 30', 'Normal');
print('-dpdf', 'CLTpNorm.pdf');


% Chi squared plot
xs = linspace(0, 200, 10000);
f9 = 100/9;
y9 = pdf('chi2', xs/f9, 9);
f19 = 100/19;
y19 = pdf('chi2', xs/f19, 19);
f99 = 100/99;
y99 = pdf('chi2', xs/f99, 99);
close all;
plot(xs, y9/f9, 'LineWidth', 3);
set(gca, 'FontSize', 24);
hold on;
plot(xs, y19/f19, 'LineWidth', 3);
plot(xs, y99/f99, 'LineWidth', 3);
title('Empirisk varians', 'FontSize', 28);
ylabel('Sannsynlighetstetthet', 'FontSize', 24)
legend('n = 10', 'n = 20', 'n = 100')
print('-dpdf', 'Variance.pdf');
