%% SL 5
clc, clear;
N = 6;
F = 1;
for n = 1:N
F = F*n;
end

prod(1:N)

%% SL 9
clc, clear;
N = 100; % calculate up to 100
k = 1; % start with 1
s = 0; % allocation for final sum
while k <= N
s = s + k; % add current value to the sum
k = k + 1; % move to the next value
end

sum(1:N)

%% SL 13
clc, clear
M = 100;
N = 20;

A = nan(M, N);

for thisM = 1:M
    for thisN = 1:N
        A(thisM, thisN) = (thisM*thisN)/4 + thisM/(2*thisN);
    end
end
pcolor(A)

%% SL 15
close all; clear;
N = 101;
om0 = 2*pi;
x = linspace(-pi/2, pi/2, N);
t = linspace(0, 4*pi, N);
I0 = cos(x);
for n = 1:N
I = I0*exp(1j*om0*t(n));
figure(1);
plot(x, real(I));
axis([x(1) x(end) -1 1]);
pause(0.1);
end

%% SL 23
clc, clear
nStudents = 40;
points = randi(100, nStudents, 1);

excellent = 0;
average = 0;
poor = 0;
for thisStudent = 1:nStudents
    if points(thisStudent) >= 80
        excellent = excellent + 1;
    elseif points(thisStudent) >= 35
        average = average + 1;
    else
        poor = poor + 1;
    end
end

disp([excellent average poor])

excellent2 = sum(points>=80)
average2 = sum(points<80 & points>=35)
poor2 = sum(points<35)

%% SL 26
clc, clear
grade = 6;
switch grade 
    case 1
        reward = 1000;
    case 2
        reward = 500;
    case 3
        reward = 200;
    case 4
        reward = 50;
    otherwise
        reward = 0;
end
disp(reward)

grade = 4;
reward = [1000 500 200 50 0];
reward(grade == 1:5)