Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Created December 25, 2013 18:04
Show Gist options
  • Save Idorobots/8125421 to your computer and use it in GitHub Desktop.
Save Idorobots/8125421 to your computer and use it in GitHub Desktop.
Final exam grades simulation.
samples = 100; % Ilość symulowanych egzaminów.
N = 128; % Ilość osób na egzaminie.
Q = 19; % Ilość pytań na egzaminie.
span = [2.0, 3.0, 3.5, 4.0, 4.5, 5.0]; % Oceny, jakie można było dostać.
R = zeros(1, N*samples); % Finalny wynik symulacji.
S = zeros(1, N); % Wynik symulacji jednego egzaminu.
mu = 0.1; % mu dla rozkładu normalnego.
sigma = 1.0; % sigma dla rozkładu normalnego.
errors = 4; % Maksymalna ilość błędów dla rozkładu jednostajnego.
for i = 1:samples;
for s = 1:N;
sum = 0;
for q = 1:Q;
a = 2 * round(normrnd(mu, sigma) - 1);
%a = randi(1 + errors) - 1; % Trzeba odkomentować, du'uh.
% Ocena pytania na egzaminie:
if a >= 2
a = 0;
elseif a >= 1
a = 2;
else
a = 4;
end
sum = sum + a;
end
% Ocena egzaminu zgodnie z regulaminem:
if sum > 90
S(s) = 5.0;
elseif sum > 80
S(s) = 4.5;
elseif sum > 70
S(s) = 4.0;
elseif sum > 60
S(s) = 3.5;
elseif sum > 50
S(s) = 3.0;
else
S(s) = 2.0;
end
end
for j = 1:N;
R((i-1)*N+j) = S(j);
end
end
figure();
subplot(2, 1, 1);
hist(R, span);
xlabel('Symulacja egzaminu');
grid on;
actual = zeros(1, N);
actual(1:N) = 2.0;
actual(1:6) = 3.0;
actual(7:62) = 3.5;
actual(63:128) = 4.0;
subplot(2, 1, 2);
hist(actual, span);
xlabel('Egzamin IS 2013');
grid on;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment