%% Almost sure convergence

figure;
hold on;

Ns = 10:10:200;
for N = Ns
    X = GOE(N); 
    plot(N, trace(X^2)/N, 'k*');
end;

plot(Ns, ones(size(Ns)));

%% Convergence in expectation

figure;
hold on;

Ns = 10:10:100;
for N = Ns

    RUNS = 1000;
    vals = zeros(1,RUNS);

    for j = 1:RUNS
        X = GOE(N); 
        vals(j) = trace(X^2)/N;
    end;

    plot(N, mean(vals), 'k*');
end;

plot(Ns, ones(size(Ns)));
plot(Ns, (Ns+1)./Ns, 'r-');


%% Convergence in probability

figure;
hold on;

for N = [100,50,10]

    RUNS = 10000;
    vals = zeros(1,RUNS);

    for j = 1:RUNS
        X = GOE(N); 
        vals(j) = trace(X^2)/N;
    end;

    disp([N, mean(vals)]);
    histogram(vals, 'Normalization', 'pdf');
end;

